From 2a773f6f1bf689938a74f292127e9ad3282f0c86 Mon Sep 17 00:00:00 2001 From: Darryl Nixon Date: Sun, 16 Jul 2023 16:31:23 -0700 Subject: [PATCH] awaits instead of a huuuge task queue --- melamine/fileops.py | 4 ++-- melamine/shred.py | 18 ++++++------------ 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/melamine/fileops.py b/melamine/fileops.py index 83afcca..72212a2 100644 --- a/melamine/fileops.py +++ b/melamine/fileops.py @@ -35,8 +35,8 @@ async def mount_bound_rglob(path: AsyncPath, mount: AsyncPath, pattern: str, ign logger.info(f"Skipping ignored subdir: {path}") return if await path.is_dir(): - if await find_mount(path) == mount: - logger.info(f"Skipping differently mounted subdir: {path} (wanted {mount}))") + if await find_mount(path) != mount: + logger.info(f"Skipping differently mounted subdir: {path} (wanted {mount})") return async for subpath in path.glob(pattern): async for subitem in mount_bound_rglob(subpath, mount, pattern, ignoredirs): diff --git a/melamine/shred.py b/melamine/shred.py index 8e42678..1a0980e 100644 --- a/melamine/shred.py +++ b/melamine/shred.py @@ -10,7 +10,7 @@ from .classes import ShredFile from .fileops import mount_bound_rglob from .logs import logger -IGNORE_GLOBAL = ("/proc", "/dev", "/sys") +IGNORE_GLOBAL = ("/proc", "/dev", "/sys", "/run") async def main(job: argparse.Namespace) -> bool: @@ -79,11 +79,10 @@ async def main(job: argparse.Namespace) -> bool: for mount_point, inodes in inodes_in_mount_points.items(): # checking for . and .. should not be neccessary w/ rglob - tasks = [] # scandir/glob/rglob doesn't play nice with FileNotFound errors, - # so let's avoid them entirely for now in /proc, /dev, and /sys + # so let's avoid them in dynamic fs areas if str(mount_point) == "/": - logger.info("Root filesystem mount seen, skipping /proc, /dev, and /sys") + logger.info("Root filesystem mount processing") async for item in mount_point.glob("*"): if await item.is_dir(): if str(item) in IGNORE_GLOBAL: @@ -96,17 +95,12 @@ async def main(job: argparse.Namespace) -> bool: no = await item.stat() logger.warning(f"{abso} inode is {no.st_ino}") logger.warning(f"is {abso} in inodes? {str(bool(no.st_ino in inodes))}") - tasks.append(check_inode_and_unlink(subitem, inodes)) + await check_inode_and_unlink(subitem, inodes) else: - tasks.append(check_inode_and_unlink(item, inodes)) + await check_inode_and_unlink(item, inodes) else: logger.info(f"Checking non-root filesystem mount: {str(mount_point)}") async for item in mount_bound_rglob(mount_point, mount_point, "*", job.ignoredir): - tasks.append(check_inode_and_unlink(item, inodes)) - done, _ = await asyncio.wait(tasks) - for task in done: - e = task.exception() - if e: - logger.trace(f"Error during find: {e}") + await check_inode_and_unlink(item, inodes) logger.info("Done")