tessl install tessl/pypi-pyfuse3@3.4.0Python 3 bindings for libfuse 3 with async I/O support
Reusable code patterns for pyfuse3 filesystems.
class FileHandleManager:
def __init__(self):
self.next_fh = 1
self.open_files = {}
self.fh_lock = trio.Lock()
async def allocate(self, inode):
async with self.fh_lock:
fh = self.next_fh
self.next_fh += 1
self.open_files[fh] = inode
return fh
async def release(self, fh):
async with self.fh_lock:
if fh in self.open_files:
del self.open_files[fh]def check_permission(self, inode_data, mode, ctx):
"""Check if ctx has permission for mode on inode."""
# Owner
if ctx.uid == inode_data['uid']:
owner_perms = (inode_data['mode'] >> 6) & 0o7
return (mode & owner_perms) == mode
# Group
if ctx.gid == inode_data['gid']:
group_perms = (inode_data['mode'] >> 3) & 0o7
return (mode & group_perms) == mode
# Others
other_perms = inode_data['mode'] & 0o7
return (mode & other_perms) == mode