melamine/melamine/filesystems/zfs.py
2023-07-16 09:30:36 -07:00

25 lines
720 B
Python

from collections.abc import Generator
from pathlib import Path
import pyzfs
class ZFSHandler:
def __init__(self, fs: str) -> None:
self.fs = "zfs"
async def get_hardlinks(self, path: Path) -> Generator:
path = path.resolve().absolute()
inode = path.stat().st_ino
zfs = pyzfs.ZFS()
dataset = zfs.get_dataset_by_path(str(path))
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(str(path)):
if entry.inode() == inode:
yield Path(entry.path())