Changeset View
Changeset View
Standalone View
Standalone View
swh/fuse/fs/entry.py
Show All 20 Lines | class EntryMode(IntEnum): | ||||
The FUSE mount is always read-only, even if permissions contradict this | The FUSE mount is always read-only, even if permissions contradict this | ||||
statement (in a context of a directory, entries are listed with permissions | statement (in a context of a directory, entries are listed with permissions | ||||
taken from the archive). | taken from the archive). | ||||
""" | """ | ||||
RDONLY_FILE = S_IFREG | 0o444 | RDONLY_FILE = S_IFREG | 0o444 | ||||
RDONLY_DIR = S_IFDIR | 0o555 | RDONLY_DIR = S_IFDIR | 0o555 | ||||
SYMLINK = S_IFLNK | 0o444 | RDONLY_LNK = S_IFLNK | 0o444 | ||||
# `cache/` sub-directories need the write permission in order to invalidate | |||||
# cached artifacts using `rm {SWHID}` | |||||
RDWR_DIR = S_IFDIR | 0o755 | |||||
@dataclass | @dataclass | ||||
class FuseEntry: | class FuseEntry: | ||||
""" Main wrapper class to manipulate virtual FUSE entries | """ Main wrapper class to manipulate virtual FUSE entries | ||||
Attributes: | Attributes: | ||||
name: entry filename | name: entry filename | ||||
Show All 14 Lines | def __post_init__(self): | ||||
# By default, let the kernel cache previously accessed data | # By default, let the kernel cache previously accessed data | ||||
self.file_info_attrs["keep_cache"] = True | self.file_info_attrs["keep_cache"] = True | ||||
async def size(self) -> int: | async def size(self) -> int: | ||||
""" Return the size (in bytes) of an entry """ | """ Return the size (in bytes) of an entry """ | ||||
raise NotImplementedError | raise NotImplementedError | ||||
async def unlink(self, name: str) -> None: | |||||
raise ValueError("Filesystem is read-only") | |||||
zack: do you really need to implement this here in this base class?
if it's just for documenting in… | |||||
def get_relative_root_path(self) -> str: | def get_relative_root_path(self) -> str: | ||||
return "../" * (self.depth - 1) | return "../" * (self.depth - 1) | ||||
def create_child(self, constructor: Any, **kwargs) -> FuseEntry: | def create_child(self, constructor: Any, **kwargs) -> FuseEntry: | ||||
return constructor(depth=self.depth + 1, fuse=self.fuse, **kwargs) | return constructor(depth=self.depth + 1, fuse=self.fuse, **kwargs) | ||||
@dataclass | @dataclass | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | |||||
@dataclass | @dataclass | ||||
class FuseSymlinkEntry(FuseEntry): | class FuseSymlinkEntry(FuseEntry): | ||||
""" FUSE virtual symlink entry | """ FUSE virtual symlink entry | ||||
Attributes: | Attributes: | ||||
target: path to symlink target | target: path to symlink target | ||||
""" | """ | ||||
mode: int = field(init=False, default=int(EntryMode.SYMLINK)) | mode: int = field(init=False, default=int(EntryMode.RDONLY_LNK)) | ||||
zackUnsubmitted Not Done Inline ActionsI know you asked me about this, but now that i rethink of it, permissions on symlinks usually don't matter, because they're never used for anything at all. zack: I know you asked me about this, but now that i rethink of it, permissions on symlinks usually… | |||||
haltodeAuthorUnsubmitted Done Inline ActionsI only changed the name to be consistent with RDONLY_FILE and RDONLY_DIR. haltode: I only changed the name to be consistent with `RDONLY_FILE` and `RDONLY_DIR`. | |||||
target: Union[str, bytes, Path] | target: Union[str, bytes, Path] | ||||
async def size(self) -> int: | async def size(self) -> int: | ||||
return len(str(self.target)) | return len(str(self.target)) | ||||
def get_target(self) -> Union[str, bytes, Path]: | def get_target(self) -> Union[str, bytes, Path]: | ||||
""" Return the path target of a symlink entry """ | """ Return the path target of a symlink entry """ | ||||
return self.target | return self.target |
do you really need to implement this here in this base class?
if it's just for documenting in the code that some sub-classes will override this, you can just raise NotImplementedError, as you do above
if this should really raise another error, than the error message here is incorrect, as it's not the entire filesystem that is read-only, but only most dirs in it