Skip to content

Commit

Permalink
BF: run: Fix expansion of cached full paths
Browse files Browse the repository at this point in the history
To avoid unnecessary re-globbing, GlobbedPaths.expand() stores the
glob results, which are relative paths.  When full=True, it also
converts these paths to absolute paths and stores that result.
However, since its introduction, the "full path, already stored" logic
has been incorrect and returns relative paths.  Update expand() to
actually use the cached full paths.

With the current run implementation, the way to trigger this codepath
is to call run *from a subdirectory* with explicit=True.

Fixes #2916.
  • Loading branch information
kyleam committed Oct 13, 2018
1 parent 3799057 commit 6f615a4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 6 additions & 3 deletions datalad/interface/run.py
Expand Up @@ -339,9 +339,12 @@ def expand(self, full=False, dot=True, refresh=False):
else:
paths = self._paths["expanded"]

if full and "expanded_full" not in self._paths:
paths = [opj(self.pwd, p) for p in paths]
self._paths["expanded_full"] = paths
if full:
if refresh or "expanded_full" not in self._paths:
paths = [opj(self.pwd, p) for p in paths]
self._paths["expanded_full"] = paths
else:
paths = self._paths["expanded_full"]

return maybe_dot + paths

Expand Down
7 changes: 7 additions & 0 deletions datalad/interface/tests/test_run.py
Expand Up @@ -852,6 +852,13 @@ def test_run_explicit(path):
ok_(ds.repo.is_dirty(path="dirt_modified"))
neq_(hexsha_initial, ds.repo.get_hexsha())

# Saving explicit outputs works from subdirectories.
subdir = opj(path, "subdir")
mkdir(subdir)
with chpwd(subdir):
run("echo insubdir >foo", explicit=True, outputs=["foo"])
ok_(ds.repo.file_has_content(opj("subdir", "foo")))


@ignore_nose_capturing_stdout
@known_failure_windows
Expand Down

0 comments on commit 6f615a4

Please sign in to comment.