mirror of
https://github.com/Garmelon/PFERD.git
synced 2025-08-12 18:42:43 +02:00
Fix cleanup deleting crawler's base directory
This commit is contained in:
@@ -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,15 +396,16 @@ 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)
|
||||||
|
|
||||||
try:
|
if delete_self:
|
||||||
path.rmdir()
|
try:
|
||||||
except OSError:
|
path.rmdir()
|
||||||
pass
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
async def _cleanup_file(self, path: Path, pure: PurePath) -> None:
|
async def _cleanup_file(self, path: Path, pure: PurePath) -> None:
|
||||||
if self._report.is_marked(pure):
|
if self._report.is_marked(pure):
|
||||||
|
Reference in New Issue
Block a user