Skip to content

Commit

Permalink
fix traverser-error on unresolved top_level_dir paths
Browse files Browse the repository at this point in the history
This commit fixes insufficient path handling in the
case of an unresolved top_level_dir path, e.g.
'/home/dataset0/../dataset0/subdataset1', and adds
a regression test for the proper handling of
unresolved paths
  • Loading branch information
christian-monch committed Jun 22, 2022
1 parent 64b7270 commit 481d8f5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion datalad_metalad/pipeline/provider/datasettraverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def __init__(self,
raise ValueError(f"{item_type.lower()} is not a known item_type. "
f"Known types are: {', '.join(known_types)}")

self.top_level_dir = Path(top_level_dir).absolute()
self.top_level_dir = Path(top_level_dir).absolute().resolve()
self.item_set = self.name_to_item_set[item_type.lower()]
self.traverse_sub_datasets = traverse_sub_datasets
self.root_dataset = require_dataset(self.top_level_dir,
Expand Down
14 changes: 13 additions & 1 deletion datalad_metalad/pipeline/provider/tests/test_datasettraverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,32 @@


@with_tempfile(mkdir=True)
def test_relative_top_level_dir(temp_dir: str):
def test_relative_and_unresolved_top_level_dir(temp_dir: str):
relative_path_str = "./some/path/dataset_0"
unresolved_path = "./some/path/../path/dataset_0"

dataset_path = Path(temp_dir) / relative_path_str
dataset_path.mkdir(parents=True)
create_dataset_proper(dataset_path)

old_path = Path.cwd()
os.chdir(str(temp_dir))

# check relative paths
traverser = DatasetTraverser(
top_level_dir=relative_path_str,
item_type="both"
)
assert_equal(traverser.fs_base_path, dataset_path)

# check unresolved paths
traverser = DatasetTraverser(
top_level_dir=Path(temp_dir) / unresolved_path,
item_type="both"
)

tuple(traverser.next_object())
assert_equal(traverser.fs_base_path, dataset_path.resolve())

# prevent teardown error due to modified working directory
os.chdir(str(old_path))
Empty file.

0 comments on commit 481d8f5

Please sign in to comment.