Skip to content

Commit a34b389

Browse files
committed
[refactor] Remove indirection with call operator
I don't understand why it existed int he first place. It adds anotherhasattr check, but as the attributes are already checked in __init__, this should only have any meaning when attributes are removed dynamically from the object after giving it to __init__. This is not supported anymore!
1 parent ff2044a commit a34b389

File tree

1 file changed

+48
-58
lines changed

1 file changed

+48
-58
lines changed

mfusepy.py

Lines changed: 48 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@ class as is to Operations, instead of just the fh field.
11771177

11781178
# Function pointer members are tested for using the
11791179
# getattr(operations, name) above but are dynamically
1180-
# invoked using self.operations(name)
1180+
# invoked using self.operations.name
11811181
if hasattr(prototype, 'argtypes'):
11821182
val = prototype(functools.partial(self._wrapper, getattr(self, name)))
11831183

@@ -1268,7 +1268,7 @@ def getattr(self, path: bytes, buf, fip): # type: ignore
12681268
return self.fgetattr(path, buf, None)
12691269

12701270
def readlink(self, path: bytes, buf, bufsize: int) -> int:
1271-
ret = self.operations('readlink', path.decode(self.encoding)).encode(self.encoding)
1271+
ret = self.operations.readlink(path.decode(self.encoding)).encode(self.encoding)
12721272

12731273
# copies a string into the given buffer
12741274
# (null terminated and truncated if necessary)
@@ -1277,24 +1277,24 @@ def readlink(self, path: bytes, buf, bufsize: int) -> int:
12771277
return 0
12781278

12791279
def mknod(self, path: bytes, mode: int, dev: int) -> int:
1280-
return self.operations('mknod', path.decode(self.encoding), mode, dev)
1280+
return self.operations.mknod(path.decode(self.encoding), mode, dev)
12811281

12821282
def mkdir(self, path: bytes, mode: int) -> int:
1283-
return self.operations('mkdir', path.decode(self.encoding), mode)
1283+
return self.operations.mkdir(path.decode(self.encoding), mode)
12841284

12851285
def unlink(self, path: bytes) -> int:
1286-
return self.operations('unlink', path.decode(self.encoding))
1286+
return self.operations.unlink(path.decode(self.encoding))
12871287

12881288
def rmdir(self, path: bytes) -> int:
1289-
return self.operations('rmdir', path.decode(self.encoding))
1289+
return self.operations.rmdir(path.decode(self.encoding))
12901290

12911291
def symlink(self, source: bytes, target: bytes) -> int:
12921292
'creates a symlink `target -> source` (e.g. ln -s source target)'
12931293

1294-
return self.operations('symlink', target.decode(self.encoding), source.decode(self.encoding))
1294+
return self.operations.symlink(target.decode(self.encoding), source.decode(self.encoding))
12951295

12961296
def _rename(self, old: bytes, new: bytes) -> int:
1297-
return self.operations('rename', old.decode(self.encoding), new.decode(self.encoding))
1297+
return self.operations.rename(old.decode(self.encoding), new.decode(self.encoding))
12981298

12991299
if fuse_version_major == 2:
13001300
rename = _rename
@@ -1306,17 +1306,17 @@ def rename(self, old: bytes, new: bytes, flags: int) -> int: # type: ignore
13061306
def link(self, source: bytes, target: bytes):
13071307
'creates a hard link `target -> source` (e.g. ln source target)'
13081308

1309-
return self.operations('link', target.decode(self.encoding), source.decode(self.encoding))
1309+
return self.operations.link(target.decode(self.encoding), source.decode(self.encoding))
13101310

13111311
if fuse_version_major == 2:
13121312

13131313
def chmod(self, path: Optional[bytes], mode: int) -> int:
1314-
return self.operations('chmod', None if path is None else path.decode(self.encoding), mode)
1314+
return self.operations.chmod(None if path is None else path.decode(self.encoding), mode)
13151315

13161316
elif fuse_version_major == 3:
13171317

13181318
def chmod(self, path: Optional[bytes], mode: int, fip) -> int: # type: ignore
1319-
return self.operations('chmod', None if path is None else path.decode(self.encoding), mode)
1319+
return self.operations.chmod(None if path is None else path.decode(self.encoding), mode)
13201320

13211321
def _chown(self, path: Optional[bytes], uid: int, gid: int) -> int:
13221322
# Check if any of the arguments is a -1 that has overflowed
@@ -1325,38 +1325,38 @@ def _chown(self, path: Optional[bytes], uid: int, gid: int) -> int:
13251325
if c_gid_t(gid + 1).value == 0:
13261326
gid = -1
13271327

1328-
return self.operations('chown', None if path is None else path.decode(self.encoding), uid, gid)
1328+
return self.operations.chown(None if path is None else path.decode(self.encoding), uid, gid)
13291329

13301330
if fuse_version_major == 2:
13311331

1332-
def chown(self, path: bytes, uid: int, gid: int) -> int:
1332+
def chown(self, path: Optional[bytes], uid: int, gid: int) -> int:
13331333
return self._chown(path, uid, gid)
13341334

13351335
elif fuse_version_major == 3:
13361336

1337-
def chown(self, path: bytes, uid: int, gid: int, fip) -> int: # type: ignore
1337+
def chown(self, path: Optional[bytes], uid: int, gid: int, fip) -> int: # type: ignore
13381338
return self._chown(path, uid, gid)
13391339

13401340
if fuse_version_major == 2:
13411341

13421342
def truncate(self, path: Optional[bytes], length: int) -> int:
1343-
return self.operations('truncate', None if path is None else path.decode(self.encoding), length)
1343+
return self.operations.truncate(None if path is None else path.decode(self.encoding), length)
13441344

13451345
elif fuse_version_major == 3:
13461346

13471347
def truncate(self, path: Optional[bytes], length: int, fip) -> int: # type: ignore
1348-
return self.operations('truncate', None if path is None else path.decode(self.encoding), length)
1348+
return self.operations.truncate(None if path is None else path.decode(self.encoding), length)
13491349

13501350
def open(self, path: bytes, fip) -> int:
13511351
fi = fip.contents
13521352
if self.raw_fi:
1353-
return self.operations('open', path.decode(self.encoding), fi)
1354-
fi.fh = self.operations('open', path.decode(self.encoding), fi.flags)
1353+
return self.operations.open(path.decode(self.encoding), fi)
1354+
fi.fh = self.operations.open(path.decode(self.encoding), fi.flags)
13551355
return 0
13561356

13571357
def read(self, path: Optional[bytes], buf, size: int, offset: int, fip) -> int:
13581358
fh = fip.contents if self.raw_fi else fip.contents.fh
1359-
ret = self.operations('read', None if path is None else path.decode(self.encoding), size, offset, fh)
1359+
ret = self.operations.read(None if path is None else path.decode(self.encoding), size, offset, fh)
13601360

13611361
if not ret:
13621362
return 0
@@ -1370,11 +1370,11 @@ def read(self, path: Optional[bytes], buf, size: int, offset: int, fip) -> int:
13701370
def write(self, path: Optional[bytes], buf, size: int, offset: int, fip) -> int:
13711371
data = ctypes.string_at(buf, size)
13721372
fh = fip.contents if self.raw_fi else fip.contents.fh
1373-
return self.operations('write', None if path is None else path.decode(self.encoding), data, offset, fh)
1373+
return self.operations.write(None if path is None else path.decode(self.encoding), data, offset, fh)
13741374

13751375
def statfs(self, path: bytes, buf) -> int:
13761376
stv = buf.contents
1377-
attrs = self.operations('statfs', path.decode(self.encoding))
1377+
attrs = self.operations.statfs(path.decode(self.encoding))
13781378
for key, val in attrs.items():
13791379
if hasattr(stv, key):
13801380
setattr(stv, key, val)
@@ -1383,19 +1383,18 @@ def statfs(self, path: bytes, buf) -> int:
13831383

13841384
def flush(self, path: Optional[bytes], fip) -> int:
13851385
fh = fip.contents if self.raw_fi else fip.contents.fh
1386-
return self.operations('flush', None if path is None else path.decode(self.encoding), fh)
1386+
return self.operations.flush(None if path is None else path.decode(self.encoding), fh)
13871387

13881388
def release(self, path: Optional[bytes], fip) -> int:
13891389
fh = fip.contents if self.raw_fi else fip.contents.fh
1390-
return self.operations('release', None if path is None else path.decode(self.encoding), fh)
1390+
return self.operations.release(None if path is None else path.decode(self.encoding), fh)
13911391

13921392
def fsync(self, path: Optional[bytes], datasync: int, fip) -> int:
13931393
fh = fip.contents if self.raw_fi else fip.contents.fh
1394-
return self.operations('fsync', None if path is None else path.decode(self.encoding), datasync, fh)
1394+
return self.operations.fsync(None if path is None else path.decode(self.encoding), datasync, fh)
13951395

13961396
def setxattr(self, path: bytes, name: bytes, value, size: int, options, *args) -> int:
1397-
return self.operations(
1398-
'setxattr',
1397+
return self.operations.setxattr(
13991398
path.decode(self.encoding),
14001399
name.decode(self.encoding),
14011400
ctypes.string_at(value, size),
@@ -1404,7 +1403,7 @@ def setxattr(self, path: bytes, name: bytes, value, size: int, options, *args) -
14041403
)
14051404

14061405
def getxattr(self, path: bytes, name: bytes, value, size: int, *args) -> int:
1407-
ret = self.operations('getxattr', path.decode(self.encoding), name.decode(self.encoding), *args)
1406+
ret = self.operations.getxattr(path.decode(self.encoding), name.decode(self.encoding), *args)
14081407

14091408
retsize = len(ret)
14101409
# allow size queries
@@ -1422,7 +1421,7 @@ def getxattr(self, path: bytes, name: bytes, value, size: int, *args) -> int:
14221421
return retsize
14231422

14241423
def listxattr(self, path: bytes, namebuf, size: int) -> int:
1425-
attrs = self.operations('listxattr', path.decode(self.encoding)) or ''
1424+
attrs = self.operations.listxattr(path.decode(self.encoding)) or ''
14261425
ret = '\x00'.join(attrs).encode(self.encoding)
14271426
if len(ret) > 0:
14281427
ret += '\x00'.encode(self.encoding)
@@ -1442,11 +1441,11 @@ def listxattr(self, path: bytes, namebuf, size: int) -> int:
14421441
return retsize
14431442

14441443
def removexattr(self, path: bytes, name: bytes) -> int:
1445-
return self.operations('removexattr', path.decode(self.encoding), name.decode(self.encoding))
1444+
return self.operations.removexattr(path.decode(self.encoding), name.decode(self.encoding))
14461445

14471446
def opendir(self, path: bytes, fip) -> int:
14481447
# Ignore raw_fi
1449-
fip.contents.fh = self.operations('opendir', path.decode(self.encoding))
1448+
fip.contents.fh = self.operations.opendir(path.decode(self.encoding))
14501449
return 0
14511450

14521451
# == About readdir and what should be returned ==
@@ -1512,7 +1511,7 @@ def opendir(self, path: bytes, fip) -> int:
15121511
# fuse.h#L263C1-L280C3
15131512
def _readdir(self, path: Optional[bytes], buf, filler, offset: int, fip) -> int:
15141513
# Ignore raw_fi
1515-
for item in self.operations('readdir', None if path is None else path.decode(self.encoding), fip.contents.fh):
1514+
for item in self.operations.readdir(None if path is None else path.decode(self.encoding), fip.contents.fh):
15161515
if isinstance(item, str):
15171516
name, st, offset = item, None, 0
15181517
else:
@@ -1549,13 +1548,11 @@ def readdir(self, path: Optional[bytes], buf, filler, offset, fip, flags) -> int
15491548

15501549
def releasedir(self, path: Optional[bytes], fip) -> int:
15511550
# Ignore raw_fi
1552-
return self.operations('releasedir', None if path is None else path.decode(self.encoding), fip.contents.fh)
1551+
return self.operations.releasedir(None if path is None else path.decode(self.encoding), fip.contents.fh)
15531552

15541553
def fsyncdir(self, path: Optional[bytes], datasync: int, fip) -> int:
15551554
# Ignore raw_fi
1556-
return self.operations(
1557-
'fsyncdir', None if path is None else path.decode(self.encoding), datasync, fip.contents.fh
1558-
)
1555+
return self.operations.fsyncdir(None if path is None else path.decode(self.encoding), datasync, fip.contents.fh)
15591556

15601557
def _init(self, conn, config) -> None:
15611558
if hasattr(self.operations, "init_with_config") and not getattr(
@@ -1578,40 +1575,40 @@ def init(self, conn, config) -> None: # type: ignore
15781575
self._init(conn, config)
15791576

15801577
def destroy(self, private_data) -> None:
1581-
return self.operations('destroy', '/')
1578+
return self.operations.destroy('/')
15821579

15831580
def access(self, path: bytes, amode: int) -> int:
1584-
return self.operations('access', path.decode(self.encoding), amode)
1581+
return self.operations.access(path.decode(self.encoding), amode)
15851582

15861583
def create(self, path: bytes, mode: int, fip) -> int:
15871584
fi = fip.contents
15881585
decoded_path = path.decode(self.encoding)
15891586

15901587
if self.raw_fi:
1591-
return self.operations('create', decoded_path, mode, fi)
1588+
return self.operations.create(decoded_path, mode, fi)
15921589
if len(inspect.signature(self.operations.create).parameters) == 2:
1593-
fi.fh = self.operations('create', decoded_path, mode)
1590+
fi.fh = self.operations.create(decoded_path, mode)
15941591
else:
1595-
fi.fh = self.operations('create', decoded_path, mode, fi.flags)
1592+
fi.fh = self.operations.create(decoded_path, mode, fi.flags)
15961593
return 0
15971594

15981595
def ftruncate(self, path: Optional[bytes], length: int, fip) -> int:
15991596
fh = fip.contents if self.raw_fi else fip.contents.fh
1600-
return self.operations('truncate', None if path is None else path.decode(self.encoding), length, fh)
1597+
return self.operations.truncate(None if path is None else path.decode(self.encoding), length, fh)
16011598

16021599
def fgetattr(self, path: Optional[bytes], buf, fip) -> int:
16031600
ctypes.memset(buf, 0, ctypes.sizeof(c_stat))
16041601

16051602
st = buf.contents
16061603
fh = (fip.contents if self.raw_fi else fip.contents.fh) if fip else fip
16071604

1608-
attrs = self.operations('getattr', None if path is None else path.decode(self.encoding), fh)
1605+
attrs = self.operations.getattr(None if path is None else path.decode(self.encoding), fh)
16091606
set_st_attrs(st, attrs, use_ns=self.use_ns)
16101607
return 0
16111608

16121609
def lock(self, path: Optional[bytes], fip, cmd: int, lock) -> int:
16131610
fh = fip.contents if self.raw_fi else fip.contents.fh
1614-
return self.operations('lock', None if path is None else path.decode(self.encoding), fh, cmd, lock)
1611+
return self.operations.lock(None if path is None else path.decode(self.encoding), fh, cmd, lock)
16151612

16161613
def _utimens(self, path: Optional[bytes], buf) -> int:
16171614
if buf:
@@ -1621,7 +1618,7 @@ def _utimens(self, path: Optional[bytes], buf) -> int:
16211618
else:
16221619
times = None
16231620

1624-
return self.operations('utimens', None if path is None else path.decode(self.encoding), times)
1621+
return self.operations.utimens(None if path is None else path.decode(self.encoding), times)
16251622

16261623
if fuse_version_major == 2:
16271624
utimens = _utimens
@@ -1631,33 +1628,31 @@ def utimens(self, path: Optional[bytes], buf, fip) -> int: # type: ignore
16311628
return self._utimens(path, buf)
16321629

16331630
def bmap(self, path: bytes, blocksize: int, idx) -> int:
1634-
return self.operations('bmap', path.decode(self.encoding), blocksize, idx)
1631+
return self.operations.bmap(path.decode(self.encoding), blocksize, idx)
16351632

16361633
def ioctl(self, path: Optional[bytes], cmd: int, arg, fip, flags: int, data) -> int:
16371634
fh = fip.contents if self.raw_fi else fip.contents.fh
1638-
return self.operations('ioctl', None if path is None else path.decode(self.encoding), cmd, arg, fh, flags, data)
1635+
return self.operations.ioctl(None if path is None else path.decode(self.encoding), cmd, arg, fh, flags, data)
16391636

16401637
def poll(self, path: Optional[bytes], fip, ph, reventsp) -> int:
16411638
fh = fip.contents if self.raw_fi else fip.contents.fh
1642-
return self.operations('poll', None if path is None else path.decode(self.encoding), fh, ph, reventsp)
1639+
return self.operations.poll(None if path is None else path.decode(self.encoding), fh, ph, reventsp)
16431640

16441641
def write_buf(self, path: bytes, buf, offset: int, fip) -> int:
16451642
fh = fip.contents if self.raw_fi else fip.contents.fh
1646-
return self.operations('write_buf', path.decode(self.encoding), buf, offset, fh)
1643+
return self.operations.write_buf(path.decode(self.encoding), buf, offset, fh)
16471644

16481645
def read_buf(self, path: bytes, bufpp, size: int, offset: int, fip) -> int:
16491646
fh = fip.contents if self.raw_fi else fip.contents.fh
1650-
return self.operations('read_buf', path.decode(self.encoding), bufpp, size, offset, fh)
1647+
return self.operations.read_buf(path.decode(self.encoding), bufpp, size, offset, fh)
16511648

16521649
def flock(self, path: bytes, fip, op: int) -> int:
16531650
fh = fip.contents if self.raw_fi else fip.contents.fh
1654-
return self.operations('flock', path.decode(self.encoding), fh, op)
1651+
return self.operations.flock(path.decode(self.encoding), fh, op)
16551652

16561653
def fallocate(self, path: Optional[bytes], mode: int, offset: int, size: int, fip) -> int:
16571654
fh = fip.contents if self.raw_fi else fip.contents.fh
1658-
return self.operations(
1659-
'fallocate', None if path is None else path.decode(self.encoding), mode, offset, size, fh
1660-
)
1655+
return self.operations.fallocate(None if path is None else path.decode(self.encoding), mode, offset, size, fh)
16611656

16621657

16631658
def _nullable_dummy_function(method):
@@ -1695,11 +1690,6 @@ class Operations:
16951690
than int.
16961691
'''
16971692

1698-
def __call__(self, op, *args):
1699-
if not hasattr(self, op):
1700-
raise FuseOSError(errno.EFAULT)
1701-
return getattr(self, op)(*args)
1702-
17031693
@_nullable_dummy_function
17041694
def access(self, path: str, amode: int) -> int:
17051695
return 0

0 commit comments

Comments
 (0)