Changeset View
Changeset View
Standalone View
Standalone View
swh/fuse/fs/entry.py
# Copyright (C) 2020 The Software Heritage developers | # Copyright (C) 2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from __future__ import annotations | from __future__ import annotations | ||||
from dataclasses import dataclass, field | from dataclasses import dataclass, field | ||||
from enum import IntEnum | from enum import IntEnum | ||||
from pathlib import Path | from pathlib import Path | ||||
import re | import re | ||||
from stat import S_IFDIR, S_IFLNK, S_IFREG | from stat import S_IFDIR, S_IFLNK, S_IFREG | ||||
from typing import Any, AsyncIterator, Optional, Pattern, Sequence, Union | from typing import Any, AsyncIterator, Dict, Optional, Pattern, Sequence, Union | ||||
# Avoid cycling import | # Avoid cycling import | ||||
Fuse = "Fuse" | Fuse = "Fuse" | ||||
class EntryMode(IntEnum): | class EntryMode(IntEnum): | ||||
""" Default entry mode and permissions for the FUSE. | """ Default entry mode and permissions for the FUSE. | ||||
Show All 18 Lines | Attributes: | ||||
inode: unique integer identifying the entry | inode: unique integer identifying the entry | ||||
""" | """ | ||||
name: str | name: str | ||||
mode: int | mode: int | ||||
depth: int | depth: int | ||||
fuse: Fuse | fuse: Fuse | ||||
inode: int = field(init=False) | inode: int = field(init=False) | ||||
file_info_attrs: Dict[str, Any] = field(init=False) | |||||
def __post_init__(self): | def __post_init__(self): | ||||
self.inode = self.fuse._alloc_inode(self) | self.inode = self.fuse._alloc_inode(self) | ||||
# By default, let the kernel cache previously accessed data | |||||
self.file_info_attrs = {"keep_cache": True} | |||||
zack: As per previous comment: do not set the dict, just override what you need.
Doing so will play… | |||||
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 | ||||
def get_relative_root_path(self) -> str: | def get_relative_root_path(self) -> str: | ||||
return "../" * (self.depth - 1) | return "../" * (self.depth - 1) | ||||
▲ Show 20 Lines • Show All 83 Lines • Show Last 20 Lines |
As per previous comment: do not set the dict, just override what you need.
Doing so will play nicer with mixins, inheritance, etc.