Skip to content

Commit

Permalink
dvcfs: handle new workspace subdirectories in walk (#6811)
Browse files Browse the repository at this point in the history
1. add try-catch to catch KeyError exception while walking dvc folder
2. Fix #6695

Co-authored-by: Zhenyu Gao <[email protected]>
  • Loading branch information
eggqq007 and Zhenyu Gao authored Oct 19, 2021
1 parent 9e57d1c commit 6d96ecb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
23 changes: 13 additions & 10 deletions dvc/fs/dvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,19 @@ def _walk(self, root, trie, topdown=True, **kwargs):
self._add_dir(trie, out, **kwargs)

root_len = len(root.parts)
for key, out in trie.iteritems(prefix=root.parts): # noqa: B301
if key == root.parts:
continue

name = key[root_len]
if len(key) > root_len + 1 or (out and out.is_dir_checksum):
dirs.add(name)
continue

files.append(name)
try:
for key, out in trie.iteritems(prefix=root.parts): # noqa: B301
if key == root.parts:
continue

name = key[root_len]
if len(key) > root_len + 1 or (out and out.is_dir_checksum):
dirs.add(name)
continue

files.append(name)
except KeyError:
pass

assert topdown
dirs = list(dirs)
Expand Down
12 changes: 12 additions & 0 deletions tests/func/test_ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@ def test_ls_repo_dvc_only_recursive(tmp_dir, dvc, scm):
)


def test_ls_repo_with_new_path_dir(tmp_dir, dvc, scm):
tmp_dir.scm_gen(FS_STRUCTURE, commit="init")
tmp_dir.dvc_gen({"mysub": {}}, commit="dvc")
tmp_dir.gen({"mysub/sub": {"foo": "content"}})

files = Repo.ls(os.fspath(tmp_dir), path="mysub/sub")
match_files(
files,
((("foo",), False),),
)


def test_ls_repo_with_path_dir(tmp_dir, dvc, scm):
tmp_dir.scm_gen(FS_STRUCTURE, commit="init")
tmp_dir.dvc_gen(DVC_STRUCTURE, commit="dvc")
Expand Down

0 comments on commit 6d96ecb

Please sign in to comment.