better readonly handling, file caching bug fixed

This commit is contained in:
Mattia Mascarello 2023-05-08 16:01:13 +02:00
parent 6930e8a25e
commit 0128b1cbbe
2 changed files with 24 additions and 20 deletions

View File

@ -1,3 +1,4 @@
import os
import stat import stat
import sys import sys
import time import time
@ -79,21 +80,24 @@ class FSNode:
def to_stat_struct(self): def to_stat_struct(self):
if self.is_dir: if self.is_dir:
return dict( return dict(
st_mode=(stat.S_IFDIR | 0o755), st_mode=(stat.S_IFDIR | 0o555),
st_ctime=time.time(), st_ctime=time.time(),
st_mtime=time.time(), st_mtime=time.time(),
st_atime=time.time(), st_atime=time.time(),
st_nlink=2, st_nlink=len(self.children),
st_uid=os.getuid(),
st_gid=os.getgid()
) )
else: else:
return dict( return dict(
st_mode=(stat.S_IFREG | 0o755), st_mode=(stat.S_IFREG | 0o555),
st_ctime=time.time(), st_ctime=time.time(),
st_mtime=time.time(), st_mtime=time.time(),
st_atime=time.time(), st_atime=time.time(),
st_nlink=2, st_nlink=2,
st_size=self.size st_size=self.size,
st_uid=os.getuid(),
st_gid=os.getgid()
) )
def find_child_by_name(self, name: str): def find_child_by_name(self, name: str):
@ -216,13 +220,13 @@ class FSNode:
link_hash = FSNode.hash_link_to(self.linkTo) link_hash = FSNode.hash_link_to(self.linkTo)
if link_hash not in fileCache.keys(): if link_hash not in fileCache.keys():
if isinstance(self.linkTo, HTMLContentMap): if isinstance(self.linkTo, HTMLContentMap):
fileCache[self.linkTo] = {"datetime": time.time(), "content": self.linkTo.markdown_make().encode()} fileCache[link_hash] = {"datetime": time.time(), "content": self.linkTo.markdown_make().encode()}
elif isinstance(self.linkTo, UrlLink): elif isinstance(self.linkTo, UrlLink):
fileCache[self.linkTo] = {"datetime": time.time(), "content": self.linkTo.url.encode()} fileCache[link_hash] = {"datetime": time.time(), "content": self.linkTo.url.encode()}
elif isinstance(self.linkTo, FileLink): elif isinstance(self.linkTo, FileLink):
r = requests.get(self.linkTo.url + "&token=" + mo.token) r = requests.get(self.linkTo.url + "&token=" + mo.token)
fileCache[self.linkTo] = {"datetime": time.time(), "content": r.content} fileCache[link_hash] = {"datetime": time.time(), "content": r.content}
return fileCache[self.linkTo]["content"][offset:offset + size] return fileCache[link_hash]["content"][offset:offset + size]
@staticmethod @staticmethod
def from_moodle(moodle: Moodle): def from_moodle(moodle: Moodle):

View File

@ -1,5 +1,6 @@
from errno import ENOENT, EACCES from errno import ENOENT, EACCES
import fuse
from fuse import LoggingMixIn, Operations, FuseOSError from fuse import LoggingMixIn, Operations, FuseOSError
from FSNode import FSNode from FSNode import FSNode
@ -14,13 +15,13 @@ class MoodleFS(LoggingMixIn, Operations):
self.tree = FSNode.from_moodle(self.moodle) self.tree = FSNode.from_moodle(self.moodle)
def chmod(self, path, mode): def chmod(self, path, mode):
return 0 # makes no sense raise fuse.FuseOSError(EACCES)
def chown(self, path, uid, gid): def chown(self, path, uid, gid):
return 0 # makes no sense raise fuse.FuseOSError(EACCES)
def create(self, path, mode): def create(self, path, mode):
return 0 # makes no sense raise fuse.FuseOSError(EACCES)
def getattr(self, path, fh=None): def getattr(self, path, fh=None):
s = self.tree.resolve_path(path) s = self.tree.resolve_path(path)
@ -32,11 +33,10 @@ class MoodleFS(LoggingMixIn, Operations):
pass pass
def listxattr(self, path): def listxattr(self, path):
attrs = self.files[path].get('attrs', {})
return [] return []
def mkdir(self, path, mode): def mkdir(self, path, mode):
return EACCES raise fuse.FuseOSError(EACCES)
def open(self, path, flags): def open(self, path, flags):
return 120 return 120
@ -55,10 +55,10 @@ class MoodleFS(LoggingMixIn, Operations):
pass pass
def rename(self, old, new): def rename(self, old, new):
return EACCES raise fuse.FuseOSError(EACCES)
def rmdir(self, path): def rmdir(self, path):
return EACCES raise fuse.FuseOSError(EACCES)
def setxattr(self, path, name, value, options, position=0): def setxattr(self, path, name, value, options, position=0):
pass pass
@ -67,16 +67,16 @@ class MoodleFS(LoggingMixIn, Operations):
return dict(f_bsize=512, f_blocks=4096, f_bavail=2048) return dict(f_bsize=512, f_blocks=4096, f_bavail=2048)
def symlink(self, target, source): def symlink(self, target, source):
return EACCES raise fuse.FuseOSError(EACCES)
def truncate(self, path, length, fh=None): def truncate(self, path, length, fh=None):
return EACCES raise fuse.FuseOSError(EACCES)
def unlink(self, path): def unlink(self, path):
return EACCES raise fuse.FuseOSError(EACCES)
def utimens(self, path, times=None): def utimens(self, path, times=None):
pass pass
def write(self, path, data, offset, fh): def write(self, path, data, offset, fh):
return EACCES raise fuse.FuseOSError(EACCES)