Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dvcfs: handle new workspace subdirectories in walk #6811

Merged
merged 1 commit into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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