island: Remove isfile() check from get_file_descriptor_for_new_secure_file()

get_file_descriptor_for_new_secure_file() should return a file
descriptor. If the file already exists, this function would return
nothing, potentially causing issues with whatever relies on this
function's output.
This commit is contained in:
Mike Salvatore 2021-06-15 13:12:18 -04:00
parent 80bfd90074
commit 327ff7a626
2 changed files with 7 additions and 7 deletions

View File

@ -55,11 +55,10 @@ def _create_secure_directory_windows(path: str):
def get_file_descriptor_for_new_secure_file(path: str) -> int:
if not os.path.isfile(path):
if is_windows_os():
return _get_file_descriptor_for_new_secure_file_windows(path)
else:
return _get_file_descriptor_for_new_secure_file_linux(path)
if is_windows_os():
return _get_file_descriptor_for_new_secure_file_windows(path)
else:
return _get_file_descriptor_for_new_secure_file_linux(path)
def _get_file_descriptor_for_new_secure_file_linux(path: str) -> int:

View File

@ -98,8 +98,9 @@ def test_create_secure_directory__perm_windows(test_path):
def test_create_secure_file__already_created(test_path):
os.close(os.open(test_path, os.O_CREAT, stat.S_IRWXU))
assert os.path.isfile(test_path)
# test fails if any exceptions are thrown
get_file_descriptor_for_new_secure_file(test_path)
with pytest.raises(Exception):
get_file_descriptor_for_new_secure_file(test_path)
def test_create_secure_file__no_parent_dir(test_path_nested):