forked from p15670423/monkey
Island: Raise RemovalError in LocalStorageFileRepository.delete_file()
This commit is contained in:
parent
cd1481e4fe
commit
da1339e410
|
@ -48,6 +48,7 @@ class IFileRepository(metaclass=abc.ABCMeta):
|
||||||
|
|
||||||
:param unsafe_file_name: An unsanitized file name that identifies the file to be deleted
|
: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 ValueError: If the file name is an attempted directory traversal
|
||||||
|
:raises RemovalError: If an error was encountered while attempting to remove a file
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ from pathlib import Path
|
||||||
from typing import BinaryIO
|
from typing import BinaryIO
|
||||||
|
|
||||||
from common.utils.file_utils import get_all_regular_files_in_directory
|
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 monkey_island.cc.server_utils.file_utils import create_secure_directory
|
||||||
|
|
||||||
from . import IFileRepository, i_file_repository
|
from . import IFileRepository, i_file_repository
|
||||||
|
@ -66,6 +66,8 @@ class LocalStorageFileRepository(IFileRepository):
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
# This method is idempotent.
|
# This method is idempotent.
|
||||||
pass
|
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):
|
def _get_safe_file_path(self, unsafe_file_name: str):
|
||||||
# Remove any path information from the file name.
|
# Remove any path information from the file name.
|
||||||
|
|
Loading…
Reference in New Issue