Skip to content

Commit

Permalink
Catch different bucket case.
Browse files Browse the repository at this point in the history
  • Loading branch information
SpacemanPaul committed Jul 23, 2024
1 parent 6a69863 commit 182d69f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions apps/dc_tools/odc/apps/dc_tools/_stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,16 @@ def _find_self_href(item: Document) -> str:
def _get_relative_path(asset_href, self_link):
if self_link is None:
return asset_href
# elif urlparse(self_link).netloc != urlparse(asset_href).netloc:
# # files are not stored in same domain (e.g. diferent buckets)
# # therefore use the absolute path
# return asset_href
self_parts = urlparse(self_link)
href_parts = urlparse(asset_href)

self_path = urlparse(self_link).path
href_path = urlparse(asset_href).path
if self_parts.netloc.split('.')[0] != href_parts.netloc.split('.')[0]:
# files are not stored with same hostname (e.g. different buckets)
# therefore use the absolute path
return asset_href

try:
return str(Path(href_path).relative_to(Path(self_path).parent))
return str(Path(href_parts.path).relative_to(Path(self_parts.path).parent))
except ValueError:
# if it's not relative, keep as an absolute link
return asset_href
Expand Down

0 comments on commit 182d69f

Please sign in to comment.