melamine/melamine/filesystems/zfs.py
2023-07-16 12:59:30 -07:00

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())