diff --git a/melamine/classes.py b/melamine/classes.py index 03fb411..5832e0d 100644 --- a/melamine/classes.py +++ b/melamine/classes.py @@ -14,22 +14,6 @@ from .fileops import mount_to_fs_handler from .logs import logger -async def get_all_hardlinks(paths: Set[Path]) -> None: - for path in paths: - if isinstance(path, ShredFile): - logger.info(f"Getting hardlinks for {path}") - hardlink_count = 0 - path.hardlinks = set() - async for link in path.fs_handler.get_hardlinks(path.absolute_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): - path.contents = await get_all_hardlinks(path.contents) - return paths - - class AsyncObject(object): async def __new__(cls, *a, **kw): instance = super().__new__(cls) @@ -160,3 +144,19 @@ class ShredFile(AsyncObject): def __hash__(self) -> int: return hash(self.absolute_path) + + +async def get_all_hardlinks(paths: Set[Union[ShredFile, ShredDir]]) -> None: + for path in paths: + if isinstance(path, ShredFile): + logger.info(f"Getting hardlinks for {path.absolute_path}") + hardlink_count = 0 + path.hardlinks = set() + async for link in path.fs_handler.get_hardlinks(path.absolute_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.name}") + if isinstance(path, ShredDir): + path.contents = await get_all_hardlinks(path.contents) + return paths