Island: Raise RemovalError in LocalStorageFileRepository.delete_file()

This commit is contained in:
Mike Salvatore 2022-06-21 13:24:22 -04:00
parent cd1481e4fe
commit da1339e410
2 changed files with 4 additions and 1 deletions

View File

@ -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

View File

@ -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.