def __init__(self, config): self.root = realpath(config.itemsDir) self.rwlock = Lock() self.config = config self.stat = Stat() self.path = PathFactory(config)
class Loopback(LoggingMixIn, Operations): def __init__(self, config): self.root = realpath(config.itemsDir) self.rwlock = Lock() self.config = config self.stat = Stat() self.path = PathFactory(config) def getDB(self): return TagDB(self.config.dbLocation) #def __call__(self, op, path, *args): # return super(Loopback, self).__call__(op, self.root + path, *args) def access(self, path, mode): if not os.access(path, mode): raise FuseOSError(EACCES) chmod = os.chmod chown = os.chown def create(self, path, mode): return os.open(path, os.O_WRONLY | os.O_CREAT, mode) def flush(self, path, fh): return os.fsync(fh) def fsync(self, path, datasync, fh): return os.fsync(fh) def getattr(self, path, fh=None): p, filename = self.path.createForFile(path) return p.getattr(filename) getxattr = None link = None listxattr = None def mkdir(self, path, mode): p, dir = self.path.createForFile(path) p.mkdir(dir, mode) mknod = None open = os.open read = None #def readdir(self, path, fh): # return ['.', '..'] def readdir(self, path, fh): p = self.path.create(path) return p.readdir() def release(self, path, fh): return os.close(fh) def rename(self, old, new): return os.rename(old, self.root + new) rmdir = None def statfs(self, path): stv = os.statvfs(path) return dict((key, getattr(stv, key)) for key in ('f_bavail', 'f_bfree', 'f_blocks', 'f_bsize', 'f_favail', 'f_ffree', 'f_files', 'f_flag', 'f_frsize', 'f_namemax')) def symlink(self, target, source): logging.debug('link %s -> %s ?') #return os.symlink(source, target) #def truncate(self, path, length, fh=None): # with open(path, 'r+') as f: # f.truncate(length) #unlink = os.unlink #utimens = os.utime def write(self, path, data, offset, fh): with self.rwlock: os.lseek(fh, offset, 0) return os.write(fh, data) def readlink(self, path): p, filename = self.path.createForFile(path) return p.readlink(filename)