From 3e0e138caa7239761eb2a99bb4c5ee89d00d486b Mon Sep 17 00:00:00 2001 From: Darryl Nixon Date: Sun, 16 Jul 2023 13:58:29 -0700 Subject: [PATCH] Remove directories, too --- melamine/classes.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/melamine/classes.py b/melamine/classes.py index 6dc917a..90fe6f6 100644 --- a/melamine/classes.py +++ b/melamine/classes.py @@ -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)