From 02e4415cb493c6ed0e878aff5ad50a9ca72f35e5 Mon Sep 17 00:00:00 2001 From: ducklet Date: Wed, 8 Feb 2023 22:51:00 +0100 Subject: [PATCH] support type filter for ls for full paths --- metadex/metadex.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/metadex/metadex.py b/metadex/metadex.py index 4dcfc27..6761ec0 100644 --- a/metadex/metadex.py +++ b/metadex/metadex.py @@ -595,7 +595,9 @@ def _ls_files( yield models.File(**f) # type: ignore -def _ls_dir_contents(*, host: str, path: str) -> Iterable[models.File]: +def _ls_dir_contents( + *, host: str, path: str, type: "models.StatType | None" = None +) -> Iterable[models.File]: with db.transaction() as conn: @@ -606,11 +608,13 @@ def _ls_dir_contents(*, host: str, path: str) -> Iterable[models.File]: return if row["stat_type"] != "d": - yield models.File(**row) # type: ignore + if type is None or row["stat_type"] == type: + yield models.File(**row) # type: ignore return for f in db.get_files(conn, parent_id=row["id"]): - yield models.File(**f) # type: ignore + if type is None or f["stat_type"] == type: + yield models.File(**f) # type: ignore def _uses_glob(string: str) -> bool: @@ -635,7 +639,7 @@ def ls( path = path.rstrip("/") if host and path.startswith("/") and not _uses_glob(host + path): - yield from _ls_dir_contents(host=host, path=path) + yield from _ls_dir_contents(host=host, path=path, type=type) else: yield from _ls_files(host=host, path=path, type=type, match=match)