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)