mirror of
https://github.com/DarrylNixon/melamine.git
synced 2024-04-22 06:27:20 -07:00
Optimize finding
This commit is contained in:
parent
0bcbb0a4b0
commit
e04d86d3cb
1 changed files with 19 additions and 1 deletions
|
@ -1,4 +1,7 @@
|
|||
import argparse
|
||||
from collections import defaultdict
|
||||
|
||||
import aiofiles
|
||||
|
||||
from .classes import get_all_hardlinks
|
||||
from .classes import ShredDir
|
||||
|
@ -32,8 +35,21 @@ async def main(job: argparse.Namespace) -> bool:
|
|||
|
||||
# Just in case, use "find" to delete any remaining hardlinks
|
||||
# from the mount point
|
||||
logger.info("Deleting remaining hardlinks using find")
|
||||
inodes_in_mount_points = defaultdict(set)
|
||||
for path in job.paths:
|
||||
await path.delete_hardlinks_by_inode()
|
||||
inodes_in_mount_points[path.mount_point].add(path.inode)
|
||||
|
||||
for mount_point, inodes in inodes_in_mount_points.items():
|
||||
async for item in aiofiles.os.scandir(mount_point):
|
||||
if item.name == "." or item.name == "..":
|
||||
continue
|
||||
if item.stat().st_ino in inodes:
|
||||
log_buf = f"Deleting hardlink: {item.path}"
|
||||
if not job.dryrun:
|
||||
log_buf = "DRY RUN " + log_buf
|
||||
await aiofiles.os.unlink(item.path)
|
||||
logger.info(log_buf)
|
||||
|
||||
# Shred all physical files including hardlinks
|
||||
for path in job.paths:
|
||||
|
@ -41,3 +57,5 @@ async def main(job: argparse.Namespace) -> bool:
|
|||
await path.shred(hash=job.exhaustive, dryrun=job.dryrun)
|
||||
elif isinstance(path, ShredDir):
|
||||
await path.shred(hash=job.exhaustive, dryrun=job.dryrun)
|
||||
|
||||
logger.info("Done")
|
||||
|
|
Loading…
Reference in a new issue