diff --git a/monkey/monkey_island/cc/services/directory_file_storage_service.py b/monkey/monkey_island/cc/services/directory_file_storage_service.py index 35e6989f2..d6fd267fe 100644 --- a/monkey/monkey_island/cc/services/directory_file_storage_service.py +++ b/monkey/monkey_island/cc/services/directory_file_storage_service.py @@ -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. diff --git a/monkey/tests/unit_tests/monkey_island/cc/services/test_directory_file_storage_service.py b/monkey/tests/unit_tests/monkey_island/cc/services/test_directory_file_storage_service.py index 09ed308c5..07f65151d 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/services/test_directory_file_storage_service.py +++ b/monkey/tests/unit_tests/monkey_island/cc/services/test_directory_file_storage_service.py @@ -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")