Improve logic for getting hardlinks async

This commit is contained in:
Darryl Nixon 2023-07-16 10:55:05 -07:00
parent b96ad00679
commit 9ea7fdd8d1
3 changed files with 28 additions and 16 deletions

View file

@ -1,5 +1,6 @@
from .classes import ShredDir
from .classes import ShredFile
from .fileops import get_all_hardlinks
from .fileops import mount_to_fs_handler
from .logs import logger
@ -10,6 +11,7 @@ async def main(job) -> bool:
It is called by the CLI and builds a job queue based on the arguments passed.
"""
new_paths = set()
logger.info(f"job type is {type(job)}")
# Expand all directories and files, and collect mount point information
for path in job.paths:
@ -28,18 +30,9 @@ async def main(job) -> bool:
logger.info(f"Skipping directory: {path} (try -r/--recursive)")
else:
raise TypeError(f"Not a file or directory: {path}")
job.paths = new_paths
# Get hardlinks to subsequently unlink for all files
for path in job.paths:
if isinstance(path, ShredFile):
logger.info("Getting hardlinks for {path}")
hardlink_count = 0
path.hardlinks = set()
async for link in path.fs_handler.get_hardlinks(path):
hardlink_count += 1
path.hardlinks.add(link)
logger.info(f"Found hardlink: {link}")
job.paths = await get_all_hardlinks(new_paths)
# Shred all physical files including hardlinks
for path in job.paths: