From a4f9b485fdbe3e007aeef98acd7c3bfa08dcbd41 Mon Sep 17 00:00:00 2001 From: Darryl Nixon Date: Sun, 16 Jul 2023 10:58:07 -0700 Subject: [PATCH] Resolve circular import --- melamine/classes.py | 17 +++++++++++++++++ melamine/fileops.py | 19 ------------------- melamine/shred.py | 2 +- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/melamine/classes.py b/melamine/classes.py index 1b1e97c..87766c8 100644 --- a/melamine/classes.py +++ b/melamine/classes.py @@ -4,6 +4,7 @@ from collections.abc import Generator from pathlib import Path from secrets import token_bytes from typing import List +from typing import Set from typing import Union import aiofiles @@ -12,6 +13,22 @@ from .fileops import find_mount from .logs import logger +async def get_all_hardlinks(paths: Set[Path]) -> None: + for path in 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}") + logger.info(f"Found {hardlink_count} hardlinks for {path.absolute_path}") + if isinstance(path, ShredDir): + await get_all_hardlinks(path) + return paths + + class ShredDir: """Class for tracking each directory to be shredded, and its contents.""" diff --git a/melamine/fileops.py b/melamine/fileops.py index 374e1dd..6b3fc35 100644 --- a/melamine/fileops.py +++ b/melamine/fileops.py @@ -1,32 +1,13 @@ import asyncio from pathlib import Path from typing import List -from typing import Set from asyncstdlib.functools import lru_cache -from .classes import ShredDir -from .classes import ShredFile from .filesystems import FSHandlers from .logs import logger -async def get_all_hardlinks(paths: Set[Path]) -> None: - for path in 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}") - logger.info(f"Found {hardlink_count} hardlinks for {path.absolute_path}") - if isinstance(path, ShredDir): - await get_all_hardlinks(path) - return paths - - def find_mount(path: Path) -> Path: """Find the mount point for a given path.""" path = path.absolute() diff --git a/melamine/shred.py b/melamine/shred.py index 772f13e..190c541 100644 --- a/melamine/shred.py +++ b/melamine/shred.py @@ -1,6 +1,6 @@ +from .classes import get_all_hardlinks 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