diff --git a/apps/dc_tools/odc/apps/dc_tools/_stac.py b/apps/dc_tools/odc/apps/dc_tools/_stac.py index 833db0a9..d4df3a30 100644 --- a/apps/dc_tools/odc/apps/dc_tools/_stac.py +++ b/apps/dc_tools/odc/apps/dc_tools/_stac.py @@ -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