Remove directories, too

This commit is contained in:
Darryl Nixon 2023-07-16 13:58:29 -07:00
parent 79536c105e
commit 3e0e138caa

View file

@ -50,7 +50,7 @@ class ShredDir(AsyncObject):
tasks.append(ShredDir(subpath, recursive))
else:
logger.warning(f"Subdirectory found: {subpath}, skipping (see -r/--recursive))")
elif subpath.is_file():
elif await subpath.is_file():
tasks.append(ShredFile(subpath))
return set(await asyncio.gather(*tasks))
@ -64,7 +64,13 @@ class ShredDir(AsyncObject):
tasks = []
for item in self.contents:
tasks.append(item.shred(hash, dryrun))
return all(await asyncio.gather(*tasks))
try:
if all(await asyncio.gather(*tasks)):
await self.absolute_path.rmdir()
return True
except Exception as e:
logger.error(f"Directory wipe failed: {e}")
return False
def __hash__(self) -> int:
return hash(self.absolute_path)