mirror of
https://github.com/DarrylNixon/melamine.git
synced 2024-04-22 06:27:20 -07:00
25 lines
720 B
Python
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())
|