clean up proc/etc handling

This commit is contained in:
Darryl Nixon 2023-07-16 15:05:52 -07:00
parent ec136294c5
commit cff31bd483

View file

@ -9,6 +9,8 @@ from .classes import ShredDir
from .classes import ShredFile from .classes import ShredFile
from .logs import logger from .logs import logger
IGNORE_GLOBAL = set("/proc", "/dev", "/sys")
async def main(job: argparse.Namespace) -> bool: 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) job.paths = await get_all_hardlinks(new_paths)
tasks = [path.absolute() for path in job.ignoredir] tasks = [path.absolute() for path in job.ignoredir]
for path in ["/proc", "/dev", "/sys"]: for path in IGNORE_GLOBAL:
tasks.append(AsyncPath(path).absolute()) tasks.append(AsyncPath(path).absolute())
job.ignoredir = set(await asyncio.gather(*tasks)) job.ignoredir = set(await asyncio.gather(*tasks))
@ -76,14 +78,10 @@ async def main(job: argparse.Namespace) -> bool:
tasks = [] tasks = []
# scandir/glob/rglob doesn't play nice with FileNotFound errors, # 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 entirely for now in /proc, /dev, and /sys
check_paths = [mount_point / path for path in ("/proc", "/dev", "/sys")] if mount_point == "/":
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
async for item in mount_point.glob("*"): async for item in mount_point.glob("*"):
if await item.is_dir(): if await item.is_dir():
if str(item) in ("proc", "dev", "sys"): if str(item) in IGNORE_GLOBAL:
continue continue
async for subitem in item.rglob("*"): async for subitem in item.rglob("*"):
if any(str(subitem).startswith(str(path)) for path in job.ignoredir): if any(str(subitem).startswith(str(path)) for path in job.ignoredir):