support type filter for ls for full paths

This commit is contained in:
ducklet 2023-02-08 22:51:00 +01:00
parent cc38046c1b
commit 02e4415cb4

View file

@ -595,7 +595,9 @@ def _ls_files(
yield models.File(**f) # type: ignore 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: with db.transaction() as conn:
@ -606,10 +608,12 @@ def _ls_dir_contents(*, host: str, path: str) -> Iterable[models.File]:
return return
if row["stat_type"] != "d": if row["stat_type"] != "d":
if type is None or row["stat_type"] == type:
yield models.File(**row) # type: ignore yield models.File(**row) # type: ignore
return return
for f in db.get_files(conn, parent_id=row["id"]): for f in db.get_files(conn, parent_id=row["id"]):
if type is None or f["stat_type"] == type:
yield models.File(**f) # type: ignore yield models.File(**f) # type: ignore
@ -635,7 +639,7 @@ def ls(
path = path.rstrip("/") path = path.rstrip("/")
if host and path.startswith("/") and not _uses_glob(host + path): 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: else:
yield from _ls_files(host=host, path=path, type=type, match=match) yield from _ls_files(host=host, path=path, type=type, match=match)