mirror of
https://github.com/DarrylNixon/melamine.git
synced 2024-04-22 06:27:20 -07:00
ignoredir
This commit is contained in:
parent
737822fd99
commit
3282d5a655
2 changed files with 32 additions and 8 deletions
|
@ -2,6 +2,8 @@ import argparse
|
|||
import asyncio
|
||||
from collections import defaultdict
|
||||
|
||||
from aiopath import AsyncPath
|
||||
|
||||
from .classes import get_all_hardlinks
|
||||
from .classes import ShredDir
|
||||
from .classes import ShredFile
|
||||
|
@ -30,13 +32,17 @@ async def main(job: argparse.Namespace) -> bool:
|
|||
# Try to delete hardlinks based on the filesystem type
|
||||
job.paths = await get_all_hardlinks(new_paths)
|
||||
|
||||
tasks = [path.absolute() for path in job.ignoredir]
|
||||
tasks.append(AsyncPath("/proc").absolute())
|
||||
job.ignoredir = set(await asyncio.gather(*tasks))
|
||||
|
||||
# Shred all physical files including hardlinks
|
||||
for path in job.paths:
|
||||
tasks = []
|
||||
if isinstance(path, ShredFile):
|
||||
tasks.append(path.shred(hash=job.exhaustive, dryrun=job.dryrun))
|
||||
tasks.append(path.shred(hash=job.exhaustive, dryrun=job.dryrun, ignoredirs=job.ignoredir))
|
||||
elif isinstance(path, ShredDir):
|
||||
tasks.append(path.shred(hash=job.exhaustive, dryrun=job.dryrun))
|
||||
tasks.append(path.shred(hash=job.exhaustive, dryrun=job.dryrun, ignoredirs=job.ignoredir))
|
||||
done, _ = await asyncio.wait(tasks)
|
||||
for task in done:
|
||||
e = task.exception()
|
||||
|
@ -54,9 +60,9 @@ async def main(job: argparse.Namespace) -> bool:
|
|||
# on an entire filesystem might be a bit burdensome
|
||||
semaphore = asyncio.Semaphore(1024)
|
||||
|
||||
async def check_inode_and_unlink(item):
|
||||
async def check_inode_and_unlink(item, inodes):
|
||||
async with semaphore:
|
||||
if await item.stat().st_ino in inodes_in_mount_points[item.mount_point]:
|
||||
if await item.stat().st_ino in inodes:
|
||||
log_buf = f"Deleting hardlink: {item.path}"
|
||||
if not job.dryrun:
|
||||
log_buf = "DRY RUN " + log_buf
|
||||
|
@ -67,7 +73,9 @@ async def main(job: argparse.Namespace) -> bool:
|
|||
# checking for . and .. should not be neccessary w/ rglob
|
||||
tasks = []
|
||||
async for item in mount_point.rglob("*"):
|
||||
tasks.append(check_inode_and_unlink(item))
|
||||
if any(str(item).startswith(path) for path in job.ignoredir):
|
||||
continue
|
||||
tasks.append(check_inode_and_unlink(item, inodes))
|
||||
done, _ = await asyncio.wait(tasks)
|
||||
for task in done:
|
||||
e = task.exception()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue