2023-05-01 01:12:48 +02:00
|
|
|
from errno import ENOENT, EACCES
|
|
|
|
|
2023-05-08 16:01:13 +02:00
|
|
|
import fuse
|
2023-05-01 01:12:48 +02:00
|
|
|
from fuse import LoggingMixIn, Operations, FuseOSError
|
|
|
|
|
|
|
|
from FSNode import FSNode
|
|
|
|
|
|
|
|
# a simple read-only filesystem to-tree interface
|
|
|
|
class MoodleFS(LoggingMixIn, Operations):
|
|
|
|
'Example memory filesystem. Supports only one level of files.'
|
|
|
|
|
|
|
|
def __init__(self, moodle):
|
|
|
|
self.category_name_id_map = {}
|
|
|
|
self.moodle = moodle
|
|
|
|
self.tree = FSNode.from_moodle(self.moodle)
|
|
|
|
|
|
|
|
def chmod(self, path, mode):
|
2023-05-08 16:01:13 +02:00
|
|
|
raise fuse.FuseOSError(EACCES)
|
2023-05-01 01:12:48 +02:00
|
|
|
|
|
|
|
def chown(self, path, uid, gid):
|
2023-05-08 16:01:13 +02:00
|
|
|
raise fuse.FuseOSError(EACCES)
|
2023-05-01 01:12:48 +02:00
|
|
|
|
|
|
|
def create(self, path, mode):
|
2023-05-08 16:01:13 +02:00
|
|
|
raise fuse.FuseOSError(EACCES)
|
2023-05-01 01:12:48 +02:00
|
|
|
|
|
|
|
def getattr(self, path, fh=None):
|
|
|
|
s = self.tree.resolve_path(path)
|
|
|
|
if s is None:
|
|
|
|
raise FuseOSError(ENOENT)
|
|
|
|
return s.to_stat_struct()
|
|
|
|
|
|
|
|
def getxattr(self, path, name, position=0):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def listxattr(self, path):
|
|
|
|
return []
|
|
|
|
|
|
|
|
def mkdir(self, path, mode):
|
2023-05-08 16:01:13 +02:00
|
|
|
raise fuse.FuseOSError(EACCES)
|
2023-05-01 01:12:48 +02:00
|
|
|
|
|
|
|
def open(self, path, flags):
|
|
|
|
return 120
|
|
|
|
|
|
|
|
def read(self, path, size, offset, fh):
|
|
|
|
return self.tree.resolve_path(path).read(size, offset, self.moodle)
|
|
|
|
|
|
|
|
def readdir(self, path, fh):
|
|
|
|
dir_e = self.tree.resolve_path(path)
|
|
|
|
return ['.', '..'] + [child.name for child in dir_e.children]
|
|
|
|
|
|
|
|
def readlink(self, path):
|
2023-05-08 15:25:13 +02:00
|
|
|
pass
|
2023-05-01 01:12:48 +02:00
|
|
|
|
|
|
|
def removexattr(self, path, name):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def rename(self, old, new):
|
2023-05-08 16:01:13 +02:00
|
|
|
raise fuse.FuseOSError(EACCES)
|
2023-05-01 01:12:48 +02:00
|
|
|
|
|
|
|
def rmdir(self, path):
|
2023-05-08 16:01:13 +02:00
|
|
|
raise fuse.FuseOSError(EACCES)
|
2023-05-01 01:12:48 +02:00
|
|
|
|
|
|
|
def setxattr(self, path, name, value, options, position=0):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def statfs(self, path):
|
|
|
|
return dict(f_bsize=512, f_blocks=4096, f_bavail=2048)
|
|
|
|
|
|
|
|
def symlink(self, target, source):
|
2023-05-08 16:01:13 +02:00
|
|
|
raise fuse.FuseOSError(EACCES)
|
2023-05-01 01:12:48 +02:00
|
|
|
|
|
|
|
def truncate(self, path, length, fh=None):
|
2023-05-08 16:01:13 +02:00
|
|
|
raise fuse.FuseOSError(EACCES)
|
2023-05-01 01:12:48 +02:00
|
|
|
|
|
|
|
def unlink(self, path):
|
2023-05-08 16:01:13 +02:00
|
|
|
raise fuse.FuseOSError(EACCES)
|
2023-05-01 01:12:48 +02:00
|
|
|
|
|
|
|
def utimens(self, path, times=None):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def write(self, path, data, offset, fh):
|
2023-05-08 16:01:13 +02:00
|
|
|
raise fuse.FuseOSError(EACCES)
|