forked from p34709852/monkey
Island: Skip directories in DirectoryFileStorageService.delete_all_files
This commit is contained in:
parent
a487aa4058
commit
2f4ffad3f6
|
@ -50,5 +50,5 @@ class DirectoryFileStorageService(IFileStorageService):
|
|||
return self._storage_directory / safe_file_name
|
||||
|
||||
def delete_all_files(self):
|
||||
for file in self._storage_directory.iterdir():
|
||||
for file in filter(lambda f: f.is_file(), self._storage_directory.iterdir()):
|
||||
file.unlink()
|
||||
|
|
|
@ -106,3 +106,16 @@ def test_remove_all_files(tmp_path):
|
|||
|
||||
for file in tmp_path.iterdir():
|
||||
assert False, f"{tmp_path} was expected to be empty, but contained files"
|
||||
|
||||
|
||||
def test_remove_all_files__skip_directories(tmp_path):
|
||||
test_dir = tmp_path / "test_dir"
|
||||
test_dir.mkdir()
|
||||
for filename in ["1.txt", "2.txt", "3.txt"]:
|
||||
(tmp_path / filename).touch()
|
||||
|
||||
fss = DirectoryFileStorageService(tmp_path)
|
||||
fss.delete_all_files()
|
||||
|
||||
for file in tmp_path.iterdir():
|
||||
assert file.name == test_dir.name
|
||||
|
|
Loading…
Reference in New Issue