Skip to content

Commit 10fcbc2

Browse files
authored
fixes delete_mag for symlink mags (#1300)
1 parent 6d24a4f commit 10fcbc2

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

webknossos/Changelog.md

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

2121
### Fixed
22+
- Fixed deletion of symlinked mags. [#1300](https://github.com/scalableminds/webknossos-libs/pull/1300)
2223

2324

2425
## [2.3.3](https://github.com/scalableminds/webknossos-libs/releases/tag/v2.3.3) - 2025-05-06

webknossos/tests/dataset/test_dataset.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,6 +1997,11 @@ def test_add_symlink_mag(data_format: DataFormat) -> None:
19971997
assure_exported_properties(ds)
19981998
assure_exported_properties(original_ds)
19991999

2000+
layer.delete_mag(4)
2001+
assert Mag(4) not in layer.mags
2002+
assert not (symlink_path / "color" / "4").exists()
2003+
assert (ds_path / "color" / "4").exists()
2004+
20002005

20012006
@pytest.mark.parametrize("data_format", [DataFormat.Zarr, DataFormat.Zarr3])
20022007
def test_remote_add_symlink_layer(data_format: DataFormat) -> None:

webknossos/webknossos/dataset/layer.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,15 +860,25 @@ def delete_mag(self, mag: MagLike) -> None:
860860
raise IndexError(
861861
f"Deleting mag {mag} failed. There is no mag with this name"
862862
)
863+
mag_view = self.get_mag(mag)
863864

864865
full_path = self._mags[mag].path
865866
del self._mags[mag]
866867
self._properties.mags = [
867868
res for res in self._properties.mags if Mag(res.mag) != mag
868869
]
869870
self.dataset._export_as_json()
870-
# delete files on disk
871-
rmtree(full_path)
871+
if not mag_view.is_foreign:
872+
# delete files on disk
873+
rmtree(full_path)
874+
else:
875+
# delete symlinks only
876+
short_mag_file_path = self.path / mag.to_layer_name()
877+
long_mag_file_path = self.path / mag.to_long_layer_name()
878+
if short_mag_file_path.exists():
879+
short_mag_file_path.unlink()
880+
elif long_mag_file_path.exists():
881+
long_mag_file_path.unlink()
872882

873883
def add_copy_mag(
874884
self,

0 commit comments

Comments
 (0)