mirror of
https://github.com/Garmelon/PFERD.git
synced 2023-12-21 10:23:01 +01:00
Fix cleanup deleting crawler's base directory
This commit is contained in:
parent
53e031d9f6
commit
44ecb2fbe7
@ -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:
|
||||||
|
Loading…
Reference in New Issue
Block a user