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 sys
import time
@ -79,21 +80,24 @@ class FSNode:
def to_stat_struct(self):
if self.is_dir:
return dict(
st_mode=(stat.S_IFDIR | 0o755),
st_mode=(stat.S_IFDIR | 0o555),
st_ctime=time.time(),
st_mtime=time.time(),
st_atime=time.time(),
st_nlink=2,
st_nlink=len(self.children),
st_uid=os.getuid(),
st_gid=os.getgid()
)
else:
return dict(
st_mode=(stat.S_IFREG | 0o755),
st_mode=(stat.S_IFREG | 0o555),
st_ctime=time.time(),
st_mtime=time.time(),
st_atime=time.time(),
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):
@ -216,13 +220,13 @@ class FSNode:
link_hash = FSNode.hash_link_to(self.linkTo)
if link_hash not in fileCache.keys():
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):
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):
r = requests.get(self.linkTo.url + "&token=" + mo.token)
fileCache[self.linkTo] = {"datetime": time.time(), "content": r.content}
return fileCache[self.linkTo]["content"][offset:offset + size]
fileCache[link_hash] = {"datetime": time.time(), "content": r.content}
return fileCache[link_hash]["content"][offset:offset + size]
@staticmethod
def from_moodle(moodle: Moodle):

View File

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