Fix cleanup deleting crawler's base directory

This commit is contained in:
Joscha 2021-05-23 10:44:04 +02:00
parent 53e031d9f6
commit 44ecb2fbe7

View File

@ -385,7 +385,10 @@ class OutputDirectory:
self._report.add_file(info.path) self._report.add_file(info.path)
async def cleanup(self) -> None: async def cleanup(self) -> None:
await self._cleanup_dir(self._root, PurePath()) if not self._root.exists():
return
await self._cleanup_dir(self._root, PurePath(), delete_self=False)
async def _cleanup(self, path: Path, pure: PurePath) -> None: async def _cleanup(self, path: Path, pure: PurePath) -> None:
if path.is_dir(): if path.is_dir():
@ -393,11 +396,12 @@ class OutputDirectory:
elif path.is_file(): elif path.is_file():
await self._cleanup_file(path, pure) await self._cleanup_file(path, pure)
async def _cleanup_dir(self, path: Path, pure: PurePath) -> None: async def _cleanup_dir(self, path: Path, pure: PurePath, delete_self: bool = True) -> None:
for child in path.iterdir(): for child in path.iterdir():
pure_child = pure / child.name pure_child = pure / child.name
await self._cleanup(child, pure_child) await self._cleanup(child, pure_child)
if delete_self:
try: try:
path.rmdir() path.rmdir()
except OSError: except OSError: