SIGN IN SIGN UP
tw93 / Mole UNCLAIMED

🐹 Deep clean and optimize your Mac.

0 0 83 Shell

refactor(uninstall): split batch_uninstall_applications into phase helpers

The 800-line batch_uninstall_applications was carrying four logical phases
(scan, preview/confirm, execute, summary) in one function plus inline
trap, BTM detection, and Dock/LaunchServices finalize. Carve it into
four private helpers and keep batch_uninstall_applications as the
orchestrator that owns the cross-phase locals, the SIGINT/SIGTERM trap,
the BTM dumpbtm probe, and the post-removal background tasks.

Helpers (all underscore-prefixed; they read and write orchestrator locals
via bash dynamic scoping, so do not call them outside the orchestrator):
- _batch_scan_app_details: pre-scan, builds app_details / running_apps /
  sudo_apps / brew_cask_apps / blocked_apps, warns about blocked apps.
- _batch_preview_and_confirm: prints the preview block, prompts the user,
  establishes the sudo session. Returns 0 to continue, 2 on user cancel,
  1 if sudo authorization was denied. The orchestrator translates these
  back to the original return codes.
- _batch_execute_removals: the per-app removal loop including launch
  services teardown, login item removal, force_kill_app, brew/sudo/normal
  mole_delete dispatch, leftover detection, defaults clearing, and the
  per-app success/failure tally.
- _batch_render_summary: composes the summary block (success line,
  failed apps, Local Network / system extension / Background Items /
  still-running warnings) and emits print_summary_block.

Behavior is preserved end to end. The only subtlety is the INT/TERM trap:
in the pre-refactor code, `return 130` exited batch_uninstall_applications
directly. Now the trap fires inside a helper, so `return 130` only exits
that helper. The trap also sets _batch_interrupted=1, and the orchestrator
checks the flag after every helper call and re-emits return 130, which
gives callers the same exit semantics they had before.

Tests: tests/uninstall.bats, tests/uninstall_safety.bats,
tests/uninstall_naming_variants.bats, tests/uninstall_remove_file_list.bats,
tests/uninstall_scan_bash32.bats, tests/brew_uninstall.bats - 95/95 pass.
T
Tw93 committed
bd07c8967bc553bc5f47eb9722cd7c76a031b934
Parent: bbc98f3