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

The paths endpoint now also includes links #88

Merged
merged 1 commit into from
Feb 13, 2024
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
6 changes: 3 additions & 3 deletions h5grove/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,16 +320,16 @@ def get_list_of_paths(

names = []

def get_path(name: str):
full_path = hdf_path_join(base_path, name)
def get_path(name: bytes):
full_path = hdf_path_join(base_path, name.decode())
content = create_content(f, full_path, resolve_links)
names.append(content.path)

try:
base_content = create_content(f, base_path, resolve_links)
assert isinstance(base_content, GroupContent)
names.append(base_content.path)
base_content._h5py_entity.visit(get_path)
base_content._h5py_entity.id.links.visit(get_path)
yield names
except NotFoundError as e:
raise create_error(404, str(e))
Expand Down
10 changes: 9 additions & 1 deletion test/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,11 @@ def test_paths(self, server):

with h5py.File(server.served_directory / filename, "w") as h5file:
h5file["tree/branch/fruit"] = "apple"
h5file["tree/branch/fruit_2"] = h5py.SoftLink("fruit")
h5file["tree/other_branch"] = 5
h5file["tree_2"] = "birch"
h5file["tree_2/branch"] = h5py.SoftLink("/tree/branch")
h5file["tree_2/trunk"] = "birch"
h5file["tree_3"] = h5py.ExternalLink("test2.h5", "/another_tree")

response = server.get(f"/paths/?file={filename}")
retrieved_paths = decode_response(response)
Expand All @@ -423,8 +426,12 @@ def test_paths(self, server):
"/tree",
"/tree/branch",
"/tree/branch/fruit",
"/tree/branch/fruit_2",
"/tree/other_branch",
"/tree_2",
"/tree_2/branch",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that while the paths now include link paths, it does not include the paths contained in said links if they resolve to groups (in this case /tree/branch/fruit and /tree/branch/fruit_2).

I think it is fine since we don't have to deal with duplicate paths then 🤷

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this is safe with link loops

"/tree_2/trunk",
"/tree_3",
]

response = server.get(f"/paths/?file={filename}&path=/tree/branch")
Expand All @@ -433,6 +440,7 @@ def test_paths(self, server):
assert retrieved_paths == [
"/tree/branch",
"/tree/branch/fruit",
"/tree/branch/fruit_2",
]

def test_404_on_non_existing_path(self, server):
Expand Down
Loading