Trying out aiopath

This commit is contained in:
Darryl Nixon 2023-07-16 12:59:30 -07:00
parent e04d86d3cb
commit cd91b960dd
6 changed files with 29 additions and 28 deletions

View file

@ -1,6 +1,9 @@
import ctypes
from collections.abc import Generator
from pathlib import Path
from aiopath import Path
from melamine.classes import AsyncObject
class ext2_filsys(ctypes.Structure):
@ -54,19 +57,16 @@ class EXT23Handler:
self.libext2fs.ext2fs_get_next_inode.argtypes = [ext2_inode_scan, ext2_inode_large_p]
self.libext2fs.ext2fs_get_next_inode.restype = ctypes.c_int
async def get_hardlinks(self, path: Path) -> Generator:
path = path.resolve().absolute()
inode = path.stat().st_ino
async def get_hardlinks(self, path: AsyncObject) -> Generator:
fs = ext2_filsys()
if self.libext2fs.ext2fs_open(bytes(path), 0, 0, 0, ctypes.byref(fs)) == 0:
if self.libext2fs.ext2fs_open(bytes(path.absolute_path), 0, 0, 0, ctypes.byref(fs)) == 0:
try:
scan = ext2_inode_scan()
try:
if self.libext2fs.ext2fs_open_inode_scan(fs, ctypes.byref(scan)) == 0:
inode_large = ext2_inode_large()
while self.libext2fs.ext2fs_get_next_inode(scan, ctypes.byref(inode_large)) == 0:
if inode_large.i_links_count > 1 and inode_large.i_file_acl == inode:
if inode_large.i_links_count > 1 and inode_large.i_file_acl == path.inode:
yield Path(fs.fs_mount_point) / scan.name.decode()
finally:
self.libext2fs.ext2fs_close_inode_scan(scan)