forked from p15670423/monkey
Island: Add FileRepositoryLockingDecorator
This commit is contained in:
parent
bc0c4a1c8e
commit
e3b5e0c01a
|
@ -1,6 +1,7 @@
|
|||
from .errors import RemovalError, RetrievalError, StorageError
|
||||
from .i_file_repository import FileNotFoundError, IFileRepository
|
||||
from .local_storage_file_repository import LocalStorageFileRepository
|
||||
from .file_repository_locking_decorator import FileRepositoryLockingDecorator
|
||||
from .file_repository_logging_decorator import FileRepositoryLoggingDecorator
|
||||
from .i_agent_binary_repository import IAgentBinaryRepository
|
||||
from .agent_binary_repository import AgentBinaryRepository
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
from multiprocessing import Lock
|
||||
from typing import BinaryIO
|
||||
|
||||
from . import IFileRepository
|
||||
|
||||
|
||||
class FileRepositoryLockingDecorator(IFileRepository):
|
||||
def __init__(self, file_repository: IFileRepository):
|
||||
self._file_repository = file_repository
|
||||
self._lock = Lock()
|
||||
|
||||
def save_file(self, unsafe_file_name: str, file_contents: BinaryIO):
|
||||
with self._lock:
|
||||
return self._file_repository.save_file(unsafe_file_name, file_contents)
|
||||
|
||||
def open_file(self, unsafe_file_name: str) -> BinaryIO:
|
||||
with self._lock:
|
||||
return self._file_repository.open_file(unsafe_file_name)
|
||||
|
||||
def delete_file(self, unsafe_file_name: str):
|
||||
with self._lock:
|
||||
return self._file_repository.delete_file(unsafe_file_name)
|
||||
|
||||
def delete_all_files(self):
|
||||
with self._lock:
|
||||
return self._file_repository.delete_all_files()
|
Loading…
Reference in New Issue