Changeset View
Changeset View
Standalone View
Standalone View
swh/fuse/fuse.py
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | def _alloc_inode(self, entry: FuseEntry) -> int: | ||||
self._next_inode += 1 | self._next_inode += 1 | ||||
self._inode2entry[inode] = entry | self._inode2entry[inode] = entry | ||||
# TODO add inode recycling with invocation to invalidate_inode when | # TODO add inode recycling with invocation to invalidate_inode when | ||||
# the dicts get too big | # the dicts get too big | ||||
return inode | return inode | ||||
def _remove_inode(self, inode: int) -> None: | |||||
try: | |||||
del self._inode2entry[inode] | |||||
except KeyError: | |||||
pass | |||||
def inode2entry(self, inode: int) -> FuseEntry: | def inode2entry(self, inode: int) -> FuseEntry: | ||||
""" Return the entry matching a given inode """ | """ Return the entry matching a given inode """ | ||||
try: | try: | ||||
return self._inode2entry[inode] | return self._inode2entry[inode] | ||||
except KeyError: | except KeyError: | ||||
raise pyfuse3.FUSEError(errno.ENOENT) | raise pyfuse3.FUSEError(errno.ENOENT) | ||||
▲ Show 20 Lines • Show All 169 Lines • ▼ Show 20 Lines | class Fuse(pyfuse3.Operations): | ||||
async def open( | async def open( | ||||
self, inode: int, _flags: int, _ctx: pyfuse3.RequestContext | self, inode: int, _flags: int, _ctx: pyfuse3.RequestContext | ||||
) -> pyfuse3.FileInfo: | ) -> pyfuse3.FileInfo: | ||||
""" Open an inode and return a unique file handle """ | """ Open an inode and return a unique file handle """ | ||||
# Re-use inode as file handle | # Re-use inode as file handle | ||||
self.logger.debug("open(inode=%d)", inode) | self.logger.debug("open(inode=%d)", inode) | ||||
return pyfuse3.FileInfo(fh=inode, keep_cache=True) | entry = self.inode2entry(inode) | ||||
return pyfuse3.FileInfo(fh=inode, **entry.file_info_attrs) | |||||
async def read(self, fh: int, offset: int, length: int) -> bytes: | async def read(self, fh: int, offset: int, length: int) -> bytes: | ||||
""" Read `length` bytes from file handle `fh` at position `offset` """ | """ Read `length` bytes from file handle `fh` at position `offset` """ | ||||
# open() uses inode as file handle | # open() uses inode as file handle | ||||
inode = fh | inode = fh | ||||
entry = self.inode2entry(inode) | entry = self.inode2entry(inode) | ||||
▲ Show 20 Lines • Show All 71 Lines • Show Last 20 Lines |