From e4cda7948c038a07ceaa995898374d6dffa8dc6e Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Wed, 8 Mar 2023 21:38:46 +0100 Subject: [PATCH] fix fuse --- catcli/catcli.py | 22 ++-------------------- catcli/fuser.py | 42 ++++++++++++++++++++---------------------- catcli/utils.py | 30 ++++++++++++++++++++++++++++++ tests.sh | 17 ++++++++++------- 4 files changed, 62 insertions(+), 49 deletions(-) diff --git a/catcli/catcli.py b/catcli/catcli.py index 46b4c6c..87c65a9 100755 --- a/catcli/catcli.py +++ b/catcli/catcli.py @@ -15,7 +15,6 @@ from typing import Dict, Any, List from docopt import docopt # local imports -from catcli import nodes from catcli.version import __version__ as VERSION from catcli.nodes import NodeTop, NodeAny from catcli.logger import Logger @@ -23,7 +22,7 @@ from catcli.colors import Colors from catcli.catalog import Catalog from catcli.walker import Walker from catcli.noder import Noder -from catcli.utils import ask, edit +from catcli.utils import ask, edit, path_to_search_all from catcli.fuser import Fuser from catcli.exceptions import BadFormatException, CatcliException @@ -31,8 +30,6 @@ NAME = 'catcli' CUR = os.path.dirname(os.path.abspath(__file__)) CATALOGPATH = f'{NAME}.catalog' GRAPHPATH = f'/tmp/{NAME}.dot' -SEPARATOR = '/' -WILD = '*' FORMATS = ['native', 'csv', 'csv-with-header', 'fzf-native', 'fzf-csv'] BANNER = f""" +-+-+-+-+-+-+ @@ -168,22 +165,7 @@ def cmd_ls(args: Dict[str, Any], noder: Noder, top: NodeTop) -> List[NodeAny]: """ls action""" - path = args[''] - if not path: - path = SEPARATOR - if not path.startswith(SEPARATOR): - path = SEPARATOR + path - # prepend with top node path - pre = f'{SEPARATOR}{nodes.NAME_TOP}' - if not path.startswith(pre): - path = pre + path - # ensure ends with a separator - if not path.endswith(SEPARATOR): - path += SEPARATOR - # add wild card - if not path.endswith(WILD): - path += WILD - + path = path_to_search_all(args['']) fmt = args['--format'] if fmt.startswith('fzf'): raise BadFormatException('fzf is not supported in ls, use find') diff --git a/catcli/fuser.py b/catcli/fuser.py index 6641bc2..177c075 100644 --- a/catcli/fuser.py +++ b/catcli/fuser.py @@ -15,6 +15,7 @@ import fuse # type: ignore # local imports from catcli.noder import Noder from catcli.nodes import NodeTop, NodeAny +from catcli.utils import path_to_search_all, path_to_top from catcli import nodes @@ -25,10 +26,6 @@ fh = logging.FileHandler('/tmp/fuse-catcli.log') fh.setLevel(logging.DEBUG) logger.addHandler(fh) -# globals -WILD = '*' -SEPARATOR = '/' - class Fuser: """fuse filesystem mounter""" @@ -58,9 +55,7 @@ class CatcliFilesystem(fuse.LoggingMixIn, fuse.Operations): # type: ignore def _get_entry(self, path: str) -> Optional[NodeAny]: """return the node pointed by path""" - pre = f'{SEPARATOR}{nodes.NAME_TOP}' - if not path.startswith(pre): - path = pre + path + path = path_to_top(path) found = self.noder.list(self.top, path, rec=False, fmt='native', @@ -71,13 +66,7 @@ class CatcliFilesystem(fuse.LoggingMixIn, fuse.Operations): # type: ignore def _get_entries(self, path: str) -> List[NodeAny]: """return nodes pointed by path""" - pre = f'{SEPARATOR}{nodes.NAME_TOP}' - if not path.startswith(pre): - path = pre + path - if not path.endswith(SEPARATOR): - path += SEPARATOR - if not path.endswith(WILD): - path += WILD + path = path_to_search_all(path) found = self.noder.list(self.top, path, rec=False, fmt='native', @@ -89,27 +78,36 @@ class CatcliFilesystem(fuse.LoggingMixIn, fuse.Operations): # type: ignore if not entry: return {} - curt = time() + maccess = time() mode: Any = S_IFREG + size: int = 0 if entry.type == nodes.TYPE_ARCHIVED: mode = S_IFREG + size = entry.size elif entry.type == nodes.TYPE_DIR: mode = S_IFDIR + size = entry.size + maccess = entry.maccess elif entry.type == nodes.TYPE_FILE: mode = S_IFREG + size = entry.size + maccess = entry.maccess elif entry.type == nodes.TYPE_STORAGE: mode = S_IFDIR + size = entry.size + maccess = entry.ts elif entry.type == nodes.TYPE_META: mode = S_IFREG elif entry.type == nodes.TYPE_TOP: mode = S_IFREG + mode = mode | 0o777 return { - 'st_mode': (mode), - 'st_nlink': 1, - 'st_size': 0, - 'st_ctime': curt, - 'st_mtime': curt, - 'st_atime': curt, + 'st_mode': (mode), # file type + 'st_nlink': 1, # count hard link + 'st_size': size, + 'st_ctime': maccess, # attr last modified + 'st_mtime': maccess, # content last modified + 'st_atime': maccess, # access time 'st_uid': os.getuid(), 'st_gid': os.getgid(), } @@ -122,7 +120,7 @@ class CatcliFilesystem(fuse.LoggingMixIn, fuse.Operations): # type: ignore # mountpoint curt = time() meta = { - 'st_mode': (S_IFDIR), + 'st_mode': (S_IFDIR | 0o777), 'st_nlink': 1, 'st_size': 0, 'st_ctime': curt, diff --git a/catcli/utils.py b/catcli/utils.py index dd058e8..4111df8 100644 --- a/catcli/utils.py +++ b/catcli/utils.py @@ -12,10 +12,40 @@ import subprocess import datetime # local imports +from catcli import nodes from catcli.exceptions import CatcliException SEPARATOR = '/' +WILD = '*' + + +def path_to_top(path: str) -> str: + """path pivot under top""" + pre = f'{SEPARATOR}{nodes.NAME_TOP}' + if not path.startswith(pre): + # prepend with top node path + path = pre + path + return path + + +def path_to_search_all(path: str) -> str: + """path to search for all subs""" + if not path: + path = SEPARATOR + if not path.startswith(SEPARATOR): + path = SEPARATOR + path + pre = f'{SEPARATOR}{nodes.NAME_TOP}' + if not path.startswith(pre): + # prepend with top node path + path = pre + path + if not path.endswith(SEPARATOR): + # ensure ends with a separator + path += SEPARATOR + if not path.endswith(WILD): + # add wild card + path += WILD + return path def md5sum(path: str) -> str: diff --git a/tests.sh b/tests.sh index 6719eec..0d8d145 100755 --- a/tests.sh +++ b/tests.sh @@ -11,7 +11,7 @@ set -e # pycodestyle echo "[+] pycodestyle" pycodestyle --version -pycodestyle --ignore=W605 catcli/ +pycodestyle catcli/ pycodestyle tests/ pycodestyle setup.py @@ -29,7 +29,6 @@ pyflakes setup.py # R0915: Too many statements # R0911: Too many return statements # R0903: Too few public methods -# R0801: Similar lines in 2 files # R0902: Too many instance attributes # R0201: no-self-used echo "[+] pylint" @@ -41,24 +40,28 @@ pylint -sn \ --disable=R0915 \ --disable=R0911 \ --disable=R0903 \ - --disable=R0801 \ --disable=R0902 \ --disable=R0201 \ --disable=R0022 \ catcli/ + + + +# R0801: Similar lines in 2 files +# W0212: Access to a protected member +# R0914: Too many local variables +# R0915: Too many statements pylint -sn \ + --disable=R0801 \ --disable=W0212 \ --disable=R0914 \ --disable=R0915 \ - --disable=R0801 \ tests/ pylint -sn setup.py # mypy echo "[+] mypy" -mypy \ - --strict \ - catcli/ +mypy --strict catcli/ # unittest echo "[+] unittests"