Update preset metadata in registry. Merges the provided updates with the existing entry, preserving any fields not specified. The installed_at timestamp is always preserved from the original entry. Args: pack_id: Preset ID updates: Partial me
(self, pack_id: str, updates: dict)
| 386 | self._save() |
| 387 | |
| 388 | def update(self, pack_id: str, updates: dict): |
| 389 | """Update preset metadata in registry. |
| 390 | |
| 391 | Merges the provided updates with the existing entry, preserving any |
| 392 | fields not specified. The installed_at timestamp is always preserved |
| 393 | from the original entry. |
| 394 | |
| 395 | Args: |
| 396 | pack_id: Preset ID |
| 397 | updates: Partial metadata to merge into existing metadata |
| 398 | |
| 399 | Raises: |
| 400 | KeyError: If preset is not installed |
| 401 | """ |
| 402 | packs = self.data.get("presets") |
| 403 | if not isinstance(packs, dict) or pack_id not in packs: |
| 404 | raise KeyError(f"Preset '{pack_id}' not found in registry") |
| 405 | existing = packs[pack_id] |
| 406 | # Handle corrupted registry entries (e.g., string/list instead of dict) |
| 407 | if not isinstance(existing, dict): |
| 408 | existing = {} |
| 409 | # Merge: existing fields preserved, new fields override (deep copy to prevent caller mutation) |
| 410 | merged = {**existing, **copy.deepcopy(updates)} |
| 411 | # Always preserve original installed_at based on key existence, not truthiness, |
| 412 | # to handle cases where the field exists but may be falsy (legacy/corruption) |
| 413 | if "installed_at" in existing: |
| 414 | merged["installed_at"] = existing["installed_at"] |
| 415 | else: |
| 416 | # If not present in existing, explicitly remove from merged if caller provided it |
| 417 | merged.pop("installed_at", None) |
| 418 | packs[pack_id] = merged |
| 419 | self._save() |
| 420 | |
| 421 | def restore(self, pack_id: str, metadata: dict): |
| 422 | """Restore preset metadata to registry without modifying timestamps. |