Resolve... asynchronicities :D

This commit is contained in:
Darryl Nixon 2023-07-16 13:29:49 -07:00
parent 143acbe02e
commit b61e16130d
4 changed files with 52 additions and 49 deletions

View file

@ -1,4 +1,5 @@
import argparse
import asyncio
from collections import defaultdict
from .classes import get_all_hardlinks
@ -12,21 +13,19 @@ async def main(job: argparse.Namespace) -> bool:
This is the main function for processing a shred request.
It is called by the CLI and builds a job queue based on the arguments passed.
"""
new_paths = set()
# Expand all directories and files, and collect mount point information
tasks = []
for path in job.paths:
if path.is_file():
if await path.is_file():
logger.info(f"Adding file: {path}")
new_paths.add(await ShredFile(path))
elif path.is_dir():
if job.recursive:
logger.info(f"Adding directory: {path}")
new_paths.add(await ShredDir(path))
else:
logger.info(f"Skipping directory: {path} (try -r/--recursive)")
tasks.append(ShredFile(path))
elif await path.is_dir():
logger.info(f"Adding directory: {path}")
tasks.append(ShredDir(path, recursive=job.recursive))
else:
raise TypeError(f"Not a file or directory: {path}")
new_paths = set(await asyncio.gather(*tasks))
# Try to delete hardlinks based on the filesystem type
job.paths = await get_all_hardlinks(new_paths)