Island: Ignore exception in delete_file() if file not found

This commit is contained in:
Mike Salvatore 2022-04-26 19:36:50 -04:00
parent 8f7215034d
commit a0b4dc1bcb
2 changed files with 11 additions and 1 deletions

View File

@ -40,7 +40,10 @@ class DirectoryFileStorageService(IFileStorageService):
def delete_file(self, unsafe_file_name: str):
safe_file_path = self._get_safe_file_path(unsafe_file_name)
safe_file_path.unlink()
try:
safe_file_path.unlink()
except FileNotFoundError:
pass
def _get_safe_file_path(self, unsafe_file_name: str):
# Remove any path information from the file name.

View File

@ -119,3 +119,10 @@ def test_remove_all_files__skip_directories(tmp_path):
for file in tmp_path.iterdir():
assert file.name == test_dir.name
def test_remove_nonexistant_file(tmp_path):
fss = DirectoryFileStorageService(tmp_path)
# This test will fail if this call raises an exception.
fss.delete_file("nonexistant_file.txt")