From da1339e41069a87d939637aa12895a93a662f504 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Tue, 21 Jun 2022 13:24:22 -0400 Subject: [PATCH] Island: Raise RemovalError in LocalStorageFileRepository.delete_file() --- .../cc/repository/file_storage/i_file_repository.py | 1 + .../repository/file_storage/local_storage_file_repository.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/monkey/monkey_island/cc/repository/file_storage/i_file_repository.py b/monkey/monkey_island/cc/repository/file_storage/i_file_repository.py index 73d3b4759..cfebe5c05 100644 --- a/monkey/monkey_island/cc/repository/file_storage/i_file_repository.py +++ b/monkey/monkey_island/cc/repository/file_storage/i_file_repository.py @@ -48,6 +48,7 @@ class IFileRepository(metaclass=abc.ABCMeta): :param unsafe_file_name: An unsanitized file name that identifies the file to be deleted :raises ValueError: If the file name is an attempted directory traversal + :raises RemovalError: If an error was encountered while attempting to remove a file """ pass diff --git a/monkey/monkey_island/cc/repository/file_storage/local_storage_file_repository.py b/monkey/monkey_island/cc/repository/file_storage/local_storage_file_repository.py index a766746ae..d18e029f4 100644 --- a/monkey/monkey_island/cc/repository/file_storage/local_storage_file_repository.py +++ b/monkey/monkey_island/cc/repository/file_storage/local_storage_file_repository.py @@ -4,7 +4,7 @@ from pathlib import Path from typing import BinaryIO from common.utils.file_utils import get_all_regular_files_in_directory -from monkey_island.cc.repository import RetrievalError, StorageError +from monkey_island.cc.repository import RemovalError, RetrievalError, StorageError from monkey_island.cc.server_utils.file_utils import create_secure_directory from . import IFileRepository, i_file_repository @@ -66,6 +66,8 @@ class LocalStorageFileRepository(IFileRepository): except FileNotFoundError: # This method is idempotent. pass + except Exception as err: + raise RemovalError(f"Error while attempting to remove {unsafe_file_name}: {err}") def _get_safe_file_path(self, unsafe_file_name: str): # Remove any path information from the file name.