From cff31bd4830e2a3561a54786d84c47d5a2980117 Mon Sep 17 00:00:00 2001 From: Darryl Nixon Date: Sun, 16 Jul 2023 15:05:52 -0700 Subject: [PATCH] clean up proc/etc handling --- melamine/shred.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/melamine/shred.py b/melamine/shred.py index d027dc0..c6c3523 100644 --- a/melamine/shred.py +++ b/melamine/shred.py @@ -9,6 +9,8 @@ from .classes import ShredDir from .classes import ShredFile from .logs import logger +IGNORE_GLOBAL = set("/proc", "/dev", "/sys") + async def main(job: argparse.Namespace) -> bool: """ @@ -33,7 +35,7 @@ async def main(job: argparse.Namespace) -> bool: job.paths = await get_all_hardlinks(new_paths) tasks = [path.absolute() for path in job.ignoredir] - for path in ["/proc", "/dev", "/sys"]: + for path in IGNORE_GLOBAL: tasks.append(AsyncPath(path).absolute()) job.ignoredir = set(await asyncio.gather(*tasks)) @@ -76,14 +78,10 @@ async def main(job: argparse.Namespace) -> bool: tasks = [] # scandir/glob/rglob doesn't play nice with FileNotFound errors, # so let's avoid them entirely for now in /proc, /dev, and /sys - check_paths = [mount_point / path for path in ("/proc", "/dev", "/sys")] - manual_process = any(asyncio.gather(*[path.exists() for path in check_paths])) - if manual_process: - logger.warning("Us") - # Traverse every directory in mount_point recursively except /proc, /dev, and /sys + if mount_point == "/": async for item in mount_point.glob("*"): if await item.is_dir(): - if str(item) in ("proc", "dev", "sys"): + if str(item) in IGNORE_GLOBAL: continue async for subitem in item.rglob("*"): if any(str(subitem).startswith(str(path)) for path in job.ignoredir):