mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-06 07:18:28 +01:00
fix for DVCFileSystem().ls()
This commit is contained in:
committed by
Ruslan Kuprieiev
parent
eb8999a86b
commit
4a2c4f76e5
+5
-6
@@ -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
|
||||
|
||||
@@ -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",
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user