Skip to content

Commit

Permalink
dvcfs: handle NotADirectoryError from datafs.ls (#9746)
Browse files Browse the repository at this point in the history
* dvc_fs: ignore NotADirectoryError in ls

* deps: bump dvc-data to >= 2.6.0

* add test

---------

Co-authored-by: Ruslan Kuprieiev <kupruser@gmail.com>
  • Loading branch information
Dave Berenbaum and efiop authored Jul 19, 2023
1 parent ea5f7d4 commit 41194b7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dvc/fs/dvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def ls( # pylint: disable=arguments-differ # noqa: C901
dvc_infos = {}
if dvc_fs:
dvc_path = _get_dvc_path(dvc_fs, subkey)
with suppress(FileNotFoundError):
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)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dependencies = [
"configobj>=5.0.6",
"distro>=1.3",
"dpath<3,>=2.1.0",
"dvc-data>=2.5.0,<2.6.0",
"dvc-data>=2.6.0,<2.7.0",
"dvc-http>=2.29.0",
"dvc-render>=0.3.1,<1",
"dvc-studio-client>=0.9.2,<1",
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/fs/test_dvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@ def test_isdir_mixed(tmp_dir, dvc):
assert not fs.isfile("dir")


def test_ls_dirty(tmp_dir, dvc):
tmp_dir.dvc_gen({"data": "data"})
(tmp_dir / "data").unlink()

tmp_dir.gen({"data": {"foo": "foo", "bar": "bar"}})

fs = DVCFileSystem(repo=dvc)
assert set(fs.ls("data")) == {"data/foo", "data/bar"}


@pytest.mark.parametrize(
"dvcfiles,extra_expected",
[
Expand Down

0 comments on commit 41194b7

Please sign in to comment.