Skip to content

Commit 314b622

Browse files
authored
Fix _dump_mag_path with paths of different file systems (#1298)
* Only check for relative path on same file system * Write changelog * Extract into utils function
1 parent aa02e65 commit 314b622

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

webknossos/Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ For upgrade instructions, please check the respective _Breaking Changes_ section
2020

2121
### Fixed
2222
- Fixed an issue with `Dataset.get_remote_datasets()` that causes value lookups to fail. [#1286](https://github.com/scalableminds/webknossos-libs/pull/1286)
23+
- Fixed issue with adding remote mags to local dataset due to some UPath checks failing for paths from different file systems. [#1298](https://github.com/scalableminds/webknossos-libs/pull/1298)
2324

2425

2526
## [2.3.2](https://github.com/scalableminds/webknossos-libs/releases/tag/v2.3.2) - 2025-04-25

webknossos/webknossos/dataset/layer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
named_partial,
5454
resolve_if_fs_path,
5555
rmtree,
56+
safe_is_relative_to,
5657
warn_deprecated,
5758
)
5859
from .defaults import (
@@ -230,7 +231,7 @@ def _dump_mag_path(path: Path, dataset_path: Path) -> str:
230231
path = resolve_if_fs_path(path)
231232
if str(path).startswith(str(dataset_path)):
232233
return str(path).removeprefix(str(dataset_path)).lstrip("/")
233-
if path.is_relative_to(dataset_path):
234+
if safe_is_relative_to(path, dataset_path):
234235
return str(path.relative_to(dataset_path))
235236
if isinstance(path, UPath) and path.protocol == "s3":
236237
return f"s3://{urlparse(path.storage_options['client_kwargs']['endpoint_url']).netloc}/{path.path}"

webknossos/webknossos/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,3 +466,12 @@ def check_version_in_thread() -> None:
466466
# Start the check in a daemon thread so it won't block program exit
467467
t = Thread(target=check_version_in_thread, daemon=True)
468468
t.start()
469+
470+
471+
def safe_is_relative_to(path: Path, base_path: Path) -> bool:
472+
if (
473+
(is_fs_path(path) and is_fs_path(base_path))
474+
or UPath(path).protocol == UPath(base_path).protocol
475+
) and path.is_relative_to(base_path):
476+
return True
477+
return False

0 commit comments

Comments
 (0)