Remove only obsolete Atomic hooks for one event, preserving custom hooks and the exact current Atomic definition. This lets a normal `enable` migrate older installations without requiring users to discover `--force`.
(
hooks: &mut Map<String, Value>,
event: &str,
command: &str,
status_message: Option<&str>,
timeout_sec: Option<u64>,
)
| 578 | /// and the exact current Atomic definition. This lets a normal `enable` |
| 579 | /// migrate older installations without requiring users to discover `--force`. |
| 580 | fn remove_stale_atomic_hooks_for_event( |
| 581 | hooks: &mut Map<String, Value>, |
| 582 | event: &str, |
| 583 | command: &str, |
| 584 | status_message: Option<&str>, |
| 585 | timeout_sec: Option<u64>, |
| 586 | ) { |
| 587 | let Some(groups) = hooks.get_mut(event).and_then(Value::as_array_mut) else { |
| 588 | return; |
| 589 | }; |
| 590 | |
| 591 | groups.retain_mut(|group| { |
| 592 | let Some(group_obj) = group.as_object_mut() else { |
| 593 | return true; |
| 594 | }; |
| 595 | let Some(group_hooks) = group_obj.get_mut("hooks").and_then(Value::as_array_mut) else { |
| 596 | return true; |
| 597 | }; |
| 598 | group_hooks.retain(|hook| { |
| 599 | let is_atomic = hook |
| 600 | .get("command") |
| 601 | .and_then(Value::as_str) |
| 602 | .is_some_and(is_atomic_hook); |
| 603 | !is_atomic || hook_matches_spec(hook, command, status_message, timeout_sec) |
| 604 | }); |
| 605 | !group_hooks.is_empty() |
| 606 | }); |
| 607 | } |
| 608 | |
| 609 | fn remove_atomic_hooks(hooks: &mut Map<String, Value>) { |
| 610 | for value in hooks.values_mut() { |
no test coverage detected