From 44ecb2fbe77b9c5caa6096d9b4309034b8326ba3 Mon Sep 17 00:00:00 2001 From: Joscha Date: Sun, 23 May 2021 10:44:04 +0200 Subject: [PATCH] Fix cleanup deleting crawler's base directory --- PFERD/output_dir.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/PFERD/output_dir.py b/PFERD/output_dir.py index fef6914..02d5fe8 100644 --- a/PFERD/output_dir.py +++ b/PFERD/output_dir.py @@ -385,7 +385,10 @@ class OutputDirectory: self._report.add_file(info.path) 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: if path.is_dir(): @@ -393,15 +396,16 @@ class OutputDirectory: elif path.is_file(): 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(): pure_child = pure / child.name await self._cleanup(child, pure_child) - try: - path.rmdir() - except OSError: - pass + if delete_self: + try: + path.rmdir() + except OSError: + pass async def _cleanup_file(self, path: Path, pure: PurePath) -> None: if self._report.is_marked(pure):