Skip to content

Allow for unnormalized path prefixes like /vsitar/ #208

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

Merged
merged 1 commit into from
Oct 27, 2020
Merged

Conversation

lossyrob
Copy link
Member

The logic in make_absolute_href uses os.path.abspath, which normalizes paths. This lets us translate joined paths like /home/user/../catalog.json into proper paths. However, normalizing the path will also modify the root path being joined to in ways that may not be desirable. Specifically in the case of a /vsitar/ prefix, the double slashes that are required for proper GDAL reading are removed by normalization. This commit modifies the logic in make_absolute_href to detect when the original start path is modified by a call to abspath, and if so replaces the modified version with the original version.

Fixes #180

def test_make_absolute_href_on_vsitar(self):
cat_path = '/vsitar//tmp/catalog.tar/catalog.json'
rel_path = 'some/item.json'
result = make_absolute_href(rel_path, cat_path)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor suggestion for clarity:

rel_path = 'some/item.json'
cat_path = '/vsitar//tmp/catalog.tar/catalog.json'
expected = '/vsitar//tmp/catalog.tar/some/item.json'

self.assertEqual(expected, make_absolute_href(rel_path, cat_path))

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, thanks. That is minor, but I made the change.

Can you mark PRs that have minor suggestions as approved, and use 'request changes' if there's specific changes or discussion left? Thanks!

I believe this falls into the former category, so I'll merge once CI passes.

The logic in make_absolute_href uses os.path.abspath, which normalizes
paths. This lets us translate joined paths like
/home/user/../catalog.json into proper paths. However, normalizing the
path will also modify the root path being joined to in ways that may
not be desirable. Specifically in the case of a /vsitar/ prefix, the
double slashes that are required for proper GDAL reading are removed
by normalization. This commit modifies the logic in
make_absolute_href to detect when the original start path is modified
by a call to abspath, and if so replaces the modified version with the
original version.

Fixes #180
@codecov-io
Copy link

codecov-io commented Oct 27, 2020

Codecov Report

Merging #208 into develop will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #208      +/-   ##
===========================================
+ Coverage    92.32%   92.36%   +0.03%     
===========================================
  Files           28       28              
  Lines         3349     3351       +2     
===========================================
+ Hits          3092     3095       +3     
+ Misses         257      256       -1     
Impacted Files Coverage Δ
pystac/utils.py 97.70% <100.00%> (+0.05%) ⬆️
pystac/extensions/version.py 98.26% <0.00%> (ø)
pystac/catalog.py 90.27% <0.00%> (+0.34%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1fcfb44...846eefb. Read the comment docs.

@lossyrob lossyrob merged commit d8219ee into develop Oct 27, 2020
@lossyrob lossyrob deleted the fix/180 branch October 27, 2020 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PyStac Sometimes Removes Characters from URIs
3 participants