diff --git a/tools/blender/aetheria_ships/__init__.py b/tools/blender/aetheria_ships/__init__.py index 1cf37fbd7..ccf319022 100644 --- a/tools/blender/aetheria_ships/__init__.py +++ b/tools/blender/aetheria_ships/__init__.py @@ -300,13 +300,23 @@ def _bind_collection(collection, path, ship_id, pending=None): stored = bpy.path.relpath(path) except ValueError: pass - collection["aetheria.asset_kind"] = "ship" - collection["aetheria.id"] = ship_id - collection["aetheria.ship_cc"] = stored + keys = ("aetheria.asset_kind", "aetheria.id", "aetheria.ship_cc", "aetheria.pending") + before = {key: collection[key] for key in keys if key in collection} + values = {"aetheria.asset_kind": "ship", "aetheria.id": ship_id, "aetheria.ship_cc": stored} if pending: - collection["aetheria.pending"] = pending - elif "aetheria.pending" in collection: - del collection["aetheria.pending"] + values["aetheria.pending"] = pending + try: + for key, value in values.items(): + collection[key] = value + if not pending and "aetheria.pending" in collection: + del collection["aetheria.pending"] + except Exception: + for key in keys: # the ID-property store refused a value: put every key back as it was + if key in before: + collection[key] = before[key] + elif key in collection: + del collection[key] + raise class AETHERIA_OT_bind_ship_collection(bpy.types.Operator): diff --git a/tools/blender/tests/smoke_package.py b/tools/blender/tests/smoke_package.py index e61b5c09d..726b34652 100644 --- a/tools/blender/tests/smoke_package.py +++ b/tools/blender/tests/smoke_package.py @@ -106,6 +106,43 @@ def bind_cases(ship, path, mods): if result != {"FINISHED"} or not stored.startswith("//") or not same_file(bpy.path.abspath(stored), path): raise SystemExit("Bind case same-drive: the stored path is not a resolving '//'-relative path") + # relpath raises ValueError across drives: the bind completes with the absolute path, without a second drive. + bpy.path.relpath = lambda *args, **kwargs: (_ for _ in ()).throw(ValueError("probe: path is on mount 'D:'")) + try: + result, stored = bind(ship, "cross-drive-forced") + finally: + bpy.path.relpath = relpath + if result != {"FINISHED"} or not os.path.isabs(stored) or not same_file(stored, path): + raise SystemExit("Bind case cross-drive-forced: the stored path is not the absolute .cc path") + + # A value the ID-property store refuses leaves the collection exactly as it was, bound or not. + import aetheria_ships + for label, ship_id, pending in (("bad-id", object(), None), ("bad-pending", SHIP_ID, [object()])): + for key in list(ship.keys()): + if key.startswith("aetheria."): + del ship[key] + for bound in (False, True): + if bound: + aetheria_ships._bind_collection(ship, path, SHIP_ID, ["Old", "Ref"]) + before = {key: ship[key] for key in ship.keys() if key.startswith("aetheria.")} + before = {key: (value.to_list() if hasattr(value, "to_list") else value) for key, value in before.items()} + try: + aetheria_ships._bind_collection(ship, path, ship_id, pending) + except Exception: + pass + else: + raise SystemExit(f"Bind case {label}: the store did not refuse the value") + after = {key: ship[key] for key in ship.keys() if key.startswith("aetheria.")} + after = {key: (value.to_list() if hasattr(value, "to_list") else value) for key, value in after.items()} + if after != before: + raise SystemExit(f"Bind case {label} bound={bound}: a refused bind left the collection half-bound") + aetheria_ships._bind_collection(ship, path, SHIP_ID) + for key in BIND_KEYS: + if key not in ship: + raise SystemExit("Bind case rebind: the collection lost its binding") + if "aetheria.pending" in ship: + raise SystemExit("Bind case rebind: a bind without pending kept the old pending") + other = os.environ.get("SMOKE_OTHER_DRIVE") if not other: print("BIND cross-drive skipped: SMOKE_OTHER_DRIVE is not set")