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>,
)
| 564 | /// and the exact current Atomic definition. This lets a normal `enable` |
| 565 | /// migrate older installations without requiring users to discover `--force`. |
| 566 | fn remove_stale_atomic_hooks_for_event( |
| 567 | hooks: &mut Map<String, Value>, |
| 568 | event: &str, |
| 569 | command: &str, |
| 570 | status_message: Option<&str>, |
| 571 | timeout_sec: Option<u64>, |
| 572 | ) { |
| 573 | let Some(groups) = hooks.get_mut(event).and_then(Value::as_array_mut) else { |
| 574 | return; |
| 575 | }; |
| 576 | |
| 577 | groups.retain_mut(|group| { |
| 578 | let Some(group_obj) = group.as_object_mut() else { |
| 579 | return true; |
| 580 | }; |
| 581 | let Some(group_hooks) = group_obj.get_mut("hooks").and_then(Value::as_array_mut) else { |
| 582 | return true; |
| 583 | }; |
| 584 | group_hooks.retain(|hook| { |
| 585 | let is_atomic = hook |
| 586 | .get("command") |
| 587 | .and_then(Value::as_str) |
| 588 | .is_some_and(is_atomic_hook); |
| 589 | !is_atomic || hook_matches_spec(hook, command, status_message, timeout_sec) |
| 590 | }); |
| 591 | !group_hooks.is_empty() |
| 592 | }); |
| 593 | } |
| 594 | |
| 595 | fn remove_atomic_hooks(hooks: &mut Map<String, Value>) { |
| 596 | for value in hooks.values_mut() { |
no test coverage detected