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
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)