Island: Skip directories in DirectoryFileStorageService.delete_all_files

This commit is contained in:
Mike Salvatore 2022-04-25 12:15:57 -04:00
parent a487aa4058
commit 2f4ffad3f6
2 changed files with 14 additions and 1 deletions

View File

@ -50,5 +50,5 @@ class DirectoryFileStorageService(IFileStorageService):
return self._storage_directory / safe_file_name return self._storage_directory / safe_file_name
def delete_all_files(self): 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() file.unlink()

View File

@ -106,3 +106,16 @@ def test_remove_all_files(tmp_path):
for file in tmp_path.iterdir(): for file in tmp_path.iterdir():
assert False, f"{tmp_path} was expected to be empty, but contained files" 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