fix for DVCFileSystem().ls()

This commit is contained in:
dberenbaum
2023-10-31 23:38:21 +02:00
committed by Ruslan Kuprieiev
parent eb8999a86b
commit 4a2c4f76e5
2 changed files with 22 additions and 6 deletions
+5 -6
View File
@@ -320,7 +320,7 @@ class _DVCFileSystem(AbstractFileSystem): # pylint:disable=abstract-method
with suppress(FileNotFoundError, NotADirectoryError):
for info in dvc_fs.ls(dvc_path, detail=True):
dvc_infos[dvc_fs.path.name(info["name"])] = info
dvc_exists = bool(dvc_infos) or dvc_fs.exists(dvc_path)
dvc_exists = True
fs_exists = False
fs_infos = {}
@@ -333,10 +333,13 @@ class _DVCFileSystem(AbstractFileSystem): # pylint:disable=abstract-method
fs, fs_path, detail=True, ignore_subrepos=ignore_subrepos
):
fs_infos[fs.path.name(info["name"])] = info
fs_exists = True
except (FileNotFoundError, NotADirectoryError):
pass
fs_exists = bool(fs_infos) or fs.exists(fs_path)
if not (dvc_exists or fs_exists):
# broken symlink or TreeError
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), path)
dvcfiles = kwargs.get("dvcfiles", False)
@@ -344,10 +347,6 @@ class _DVCFileSystem(AbstractFileSystem): # pylint:disable=abstract-method
paths = []
names = set(dvc_infos.keys()) | set(fs_infos.keys())
if not names and (dvc_exists or fs_exists):
# broken symlink or TreeError
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), path)
for name in names:
if not dvcfiles and _is_dvc_file(name):
continue
+17
View File
@@ -173,6 +173,23 @@ def test_ls_dirty(tmp_dir, dvc):
assert set(fs.ls("data")) == {"data/foo", "data/bar"}
def test_ls_file_not_found(tmp_dir, dvc):
tmp_dir.dvc_gen({"data": "data"})
fs = DVCFileSystem(repo=dvc)
with pytest.raises(FileNotFoundError):
fs.ls("missing")
def test_ls_dir_empty(tmp_dir, dvc):
tmp_dir.dvc_gen({"data": "data"})
empty = tmp_dir / "empty"
empty.mkdir()
fs = DVCFileSystem(repo=dvc)
assert set(fs.ls("empty")) == set()
@pytest.mark.parametrize(
"dvcfiles,extra_expected",
[