Skip to content

Commit f89869e

Browse files
committed
Fix uninstall dry-run leftover warnings
1 parent 274c0fb commit f89869e

2 files changed

Lines changed: 68 additions & 16 deletions

File tree

lib/uninstall/batch.sh

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -737,22 +737,24 @@ batch_uninstall_applications() {
737737
# and would just produce stderr noise we discard.
738738
local leftover_kb=0
739739
local -a leftover_paths=()
740-
while IFS= read -r _lf; do
741-
[[ -n "$_lf" && -e "$_lf" ]] || continue
742-
# Skip macOS-managed container stubs: containermanagerd protects
743-
# these directories via com.apple.provenance xattr; rm -rf always
744-
# fails on them by design. User data is already gone at this point.
745-
if [[ "$_lf" == */Library/Containers/* && -f "$_lf/.com.apple.containermanagerd.metadata.plist" ]]; then
746-
continue
747-
fi
748-
leftover_paths+=("$_lf")
749-
done <<< "$related_files"
750-
751-
if [[ ${#leftover_paths[@]} -gt 0 ]]; then
752-
local _du_total
753-
_du_total=$(command du -skcP "${leftover_paths[@]}" 2> /dev/null | awk 'END {print $1}')
754-
if [[ "$_du_total" =~ ^[0-9]+$ ]]; then
755-
leftover_kb=$_du_total
740+
if ! is_uninstall_dry_run; then
741+
while IFS= read -r _lf; do
742+
[[ -n "$_lf" && -e "$_lf" ]] || continue
743+
# Skip macOS-managed container stubs: containermanagerd protects
744+
# these directories via com.apple.provenance xattr; rm -rf always
745+
# fails on them by design. User data is already gone at this point.
746+
if [[ "$_lf" == */Library/Containers/* && -f "$_lf/.com.apple.containermanagerd.metadata.plist" ]]; then
747+
continue
748+
fi
749+
leftover_paths+=("$_lf")
750+
done <<< "$related_files"
751+
752+
if [[ ${#leftover_paths[@]} -gt 0 ]]; then
753+
local _du_total
754+
_du_total=$(command du -skcP "${leftover_paths[@]}" 2> /dev/null | awk 'END {print $1}')
755+
if [[ "$_du_total" =~ ^[0-9]+$ ]]; then
756+
leftover_kb=$_du_total
757+
fi
756758
fi
757759
fi
758760

tests/uninstall.bats

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,56 @@ EOF
225225
[ "$status" -eq 0 ]
226226
}
227227

228+
@test "batch_uninstall_applications dry-run does not report expected leftovers as failures" {
229+
create_app_artifacts
230+
231+
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc <<'EOF'
232+
set -euo pipefail
233+
source "$PROJECT_ROOT/lib/core/common.sh"
234+
source "$PROJECT_ROOT/lib/uninstall/batch.sh"
235+
236+
request_sudo_access() { return 0; }
237+
start_inline_spinner() { :; }
238+
stop_inline_spinner() { :; }
239+
enter_alt_screen() { :; }
240+
leave_alt_screen() { :; }
241+
hide_cursor() { :; }
242+
show_cursor() { :; }
243+
remove_apps_from_dock() { :; }
244+
pgrep() { return 1; }
245+
pkill() { return 0; }
246+
sudo() { return 0; }
247+
248+
export MOLE_DRY_RUN=1
249+
export MOLE_DELETE_MODE=trash
250+
251+
app_bundle="$HOME/Applications/TestApp.app"
252+
mkdir -p "$app_bundle"
253+
254+
selected_apps=()
255+
selected_apps+=("0|$app_bundle|TestApp|com.example.TestApp|0|Never")
256+
files_cleaned=0
257+
total_items=0
258+
total_size_cleaned=0
259+
260+
output_file="$HOME/dry_run_uninstall.log"
261+
printf '\n' | batch_uninstall_applications > "$output_file" 2>&1
262+
output=$(cat "$output_file")
263+
264+
[[ -d "$app_bundle" ]] || { echo "WRONG: dry-run removed app bundle"; cat "$output_file"; exit 1; }
265+
[[ -d "$HOME/Library/Application Support/TestApp" ]] || { echo "WRONG: dry-run removed app support"; cat "$output_file"; exit 1; }
266+
[[ -d "$HOME/Library/Caches/TestApp" ]] || { echo "WRONG: dry-run removed cache"; cat "$output_file"; exit 1; }
267+
[[ -f "$HOME/Library/Preferences/com.example.TestApp.plist" ]] || { echo "WRONG: dry-run removed prefs"; cat "$output_file"; exit 1; }
268+
269+
[[ "$output" == *"Uninstall dry run complete"* ]] || { echo "WRONG: missing dry-run summary"; cat "$output_file"; exit 1; }
270+
[[ "$output" == *"Would remove 1 app"* ]] || { echo "WRONG: missing would-remove summary"; cat "$output_file"; exit 1; }
271+
[[ "$output" != *"Could not remove"* ]] || { echo "WRONG: dry-run reported expected leftovers"; cat "$output_file"; exit 1; }
272+
[[ "$output" != *"Uninstall incomplete"* ]] || { echo "WRONG: dry-run marked incomplete"; cat "$output_file"; exit 1; }
273+
EOF
274+
275+
[ "$status" -eq 0 ]
276+
}
277+
228278
@test "force_kill_app sends only an AppleScript Quit, never a kill signal" {
229279
# run_with_timeout invokes its argv via gtimeout/timeout, which exec the
230280
# real binary and bypass bash functions, so we shadow osascript via a

0 commit comments

Comments
 (0)