island: Add os.O_EXCL flag so that an error is thrown if trying to create a file that exists

This commit is contained in:
Shreya 2021-06-14 16:49:24 +05:30
parent 8dd4bb5e17
commit 8b932e1946
1 changed files with 3 additions and 1 deletions

View File

@ -58,7 +58,9 @@ def create_secure_file(path: str):
def _create_secure_file_linux(path: str): def _create_secure_file_linux(path: str):
try: try:
flags = os.O_RDWR | os.O_CREAT # read/write, create new flags = (
os.O_RDWR | os.O_CREAT | os.O_EXCL
) # read/write, create new, throw error if file exists
mode = 0o700 # read/write/execute permissions to owner mode = 0o700 # read/write/execute permissions to owner
with os.open(path, flags, mode) as x: # noqa: F841 with os.open(path, flags, mode) as x: # noqa: F841