Skip to content

Commit

Permalink
Merge branch 'any-op'
Browse files Browse the repository at this point in the history
It was about time :D
  • Loading branch information
Paulo Costa committed Sep 28, 2015
2 parents 3cac0ab + 2a0141f commit 76b13e1
Showing 1 changed file with 19 additions and 50 deletions.
69 changes: 19 additions & 50 deletions routefs/__init__.py
Expand Up @@ -73,67 +73,36 @@ def _get_file(self, path):
result = Directory(result)
return result

def readdir(self, path, offset):
"""
If the path referred to is a directory, return the elements of
that diectory
"""
return self._get_file(path).readdir(offset)

def getattr(self, path):
"""
Return the stat information for a path
The stat information for a directory, symlink, or file is
predetermined based on which it is.
"""
return self._get_file(path).getattr()

def read(self, path, length, offset):
"""
If the path specified is a file, return the requested portion
of the file
"""
return self._get_file(path).read(length, offset)

def readlink(self, path):
"""
If the path specified is a symlink, return the target
"""
return self._get_file(path).readlink()

def write(self, path, buf, offset):
def __getattr__(self, attr):
"""
If the path specified is a file, call the appropriate member
on the file
If the requested attribute is one of the standard FUSE op,
return a function which finds the file matching the requested
path, and passes the op to the object corresponding to that
file.
"""
return self._get_file(path).write(buf, offset)
def op(path, *args):
file = self._get_file(path)
if hasattr(file, attr) and callable(getattr(file, attr)):
return getattr(file, attr)(*args)

if attr in ['getattr', 'readlink', 'readdir', 'mknod', 'mkdir',
'unlink', 'rmdir', 'symlink', 'rename', 'link', 'chmod',
'chown', 'truncate', 'utime', 'open', 'read',
'write', 'release', 'fsync', 'flush', 'getxattr',
'listxattr', 'setxattr', 'removexattr']:
return op
else:
raise AttributeError, attr


class TreeKey(object):
def getattr(self):
return -errno.EINVAL
def readdir(self, offset):
return -errno.EINVAL
def read(self, length, offset):
return -errno.EINVAL
def readlink(self):
return -errno.EINVAL
def write(self, length, offset):
return -errno.EINVAL
pass


class NoEntry(TreeKey):
def getattr(self):
return -errno.ENOENT
def readdir(self, offset):
return -errno.ENOENT
def read(self, length, offset):
return -errno.ENOENT
def readlink(self):
return -errno.ENOENT
def write(self, length, offset):
return -errno.ENOENT


class TreeEntry(TreeKey):
Expand Down

0 comments on commit 76b13e1

Please sign in to comment.