mirror of
https://github.com/DarrylNixon/melamine.git
synced 2024-04-22 06:27:20 -07:00
26 lines
732 B
Python
26 lines
732 B
Python
from collections.abc import Generator
|
|
|
|
import libzfs
|
|
from aiopath import Path
|
|
|
|
from melamine.classes import AsyncObject
|
|
|
|
|
|
class ZFSHandler:
|
|
def __init__(self) -> None:
|
|
self.fs = "zfs"
|
|
|
|
async def get_hardlinks(self, path: AsyncObject) -> Generator:
|
|
path_str = str(path.absolute_path)
|
|
|
|
zfs = libzfs.ZFS()
|
|
dataset = zfs.get_dataset_by_path(path_str)
|
|
if dataset is not None:
|
|
pool = dataset.pool
|
|
filesystem = dataset.filesystem
|
|
fs = pool.open(filesystem)
|
|
|
|
for snapshot in fs.snapshots():
|
|
for entry in snapshot.ls(path_str):
|
|
if entry.inode() == path.inode:
|
|
yield Path(entry.path())
|