mirror of
https://github.com/DarrylNixon/melamine.git
synced 2024-04-22 06:27:20 -07:00
proc is a cruel mistress
This commit is contained in:
parent
b1e9053bb4
commit
4215f4dd2c
1 changed files with 21 additions and 5 deletions
|
@ -33,7 +33,8 @@ 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]
|
||||||
tasks.append(AsyncPath("/proc").absolute())
|
for path in ["/proc", "/dev", "/sys"]:
|
||||||
|
tasks.append(AsyncPath(path).absolute())
|
||||||
job.ignoredir = set(await asyncio.gather(*tasks))
|
job.ignoredir = set(await asyncio.gather(*tasks))
|
||||||
|
|
||||||
# Shred all physical files including hardlinks
|
# Shred all physical files including hardlinks
|
||||||
|
@ -72,10 +73,25 @@ async def main(job: argparse.Namespace) -> bool:
|
||||||
for mount_point, inodes in inodes_in_mount_points.items():
|
for mount_point, inodes in inodes_in_mount_points.items():
|
||||||
# checking for . and .. should not be neccessary w/ rglob
|
# checking for . and .. should not be neccessary w/ rglob
|
||||||
tasks = []
|
tasks = []
|
||||||
async for item in mount_point.rglob("*"):
|
# scandir/glob/rglob doesn't play nice with FileNotFound errors,
|
||||||
if any(str(item).startswith(str(path)) for path in job.ignoredir):
|
# so let's avoid them entirely for now in /proc, /dev, and /sys
|
||||||
continue
|
if any((mount_point / path).exists() for path in ("/proc", "/dev", "/sys")):
|
||||||
tasks.append(check_inode_and_unlink(item, inodes))
|
# Traverse every directory in mount_point recursively except /proc, /dev, and /sys
|
||||||
|
async for item in mount_point.glob("*"):
|
||||||
|
if await item.is_dir():
|
||||||
|
if str(item) in ("proc", "dev", "sys"):
|
||||||
|
continue
|
||||||
|
async for subitem in item.rglob("*"):
|
||||||
|
if any(str(subitem).startswith(str(path)) for path in job.ignoredir):
|
||||||
|
continue
|
||||||
|
tasks.append(check_inode_and_unlink(subitem, inodes))
|
||||||
|
else:
|
||||||
|
tasks.append(check_inode_and_unlink(item, inodes))
|
||||||
|
else:
|
||||||
|
async for item in mount_point.rglob("*"):
|
||||||
|
if any(str(item).startswith(str(path)) for path in job.ignoredir):
|
||||||
|
continue
|
||||||
|
tasks.append(check_inode_and_unlink(item, inodes))
|
||||||
done, _ = await asyncio.wait(tasks)
|
done, _ = await asyncio.wait(tasks)
|
||||||
for task in done:
|
for task in done:
|
||||||
e = task.exception()
|
e = task.exception()
|
||||||
|
|
Loading…
Reference in a new issue