From dcac6a33913a5b1ae2b0ac1107e6249ac77f19a0 Mon Sep 17 00:00:00 2001 From: dekran <41975320+rans0@users.noreply.github.com> Date: Sat, 31 Jan 2026 16:37:22 +0700 Subject: [PATCH] fix: handle dotfiles in Trash cleanup (#395) Replace glob pattern with find command to properly clean dotfiles in Trash when osascript fallback is used. The old pattern ~/.Trash/* does not match files starting with "." in bash. This fix ensures that hidden files like .DS_Store, .hidden_file, etc. are properly removed when cleaning the Trash. --- cmd/analyze/heap_test.go | 1 - lib/clean/user.sh | 4 +++- tests/clean_user_core.bats | 28 ++++++++++++++++++++++++++-- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/cmd/analyze/heap_test.go b/cmd/analyze/heap_test.go index 75076c8..a31190f 100644 --- a/cmd/analyze/heap_test.go +++ b/cmd/analyze/heap_test.go @@ -150,4 +150,3 @@ func TestLargeFileHeap(t *testing.T) { } }) } - diff --git a/lib/clean/user.sh b/lib/clean/user.sh index 50d8f31..48c2be4 100644 --- a/lib/clean/user.sh +++ b/lib/clean/user.sh @@ -20,7 +20,9 @@ clean_user_essentials() { echo -e " ${GREEN}${ICON_SUCCESS}${NC} Trash · emptied, $trash_count items" note_activity else - safe_clean ~/.Trash/* "Trash" + while IFS= read -r -d '' item; do + safe_remove "$item" true || true + done < <(command find "$HOME/.Trash" -mindepth 1 -maxdepth 1 -print0 2> /dev/null || true) fi else echo -e " ${GRAY}${ICON_EMPTY}${NC} Trash · already empty" diff --git a/tests/clean_user_core.bats b/tests/clean_user_core.bats index f4d0515..306dc77 100644 --- a/tests/clean_user_core.bats +++ b/tests/clean_user_core.bats @@ -103,8 +103,6 @@ EOF [ "$status" -eq 0 ] } - - @test "clean_browsers calls expected cache paths" { run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc <<'EOF' set -euo pipefail @@ -145,3 +143,29 @@ EOF [ "$status" -eq 0 ] [[ -z "$output" ]] } + +@test "clean_user_essentials includes dotfiles in Trash cleanup" { + mkdir -p "$HOME/.Trash" + touch "$HOME/.Trash/.hidden_file" + touch "$HOME/.Trash/.DS_Store" + touch "$HOME/.Trash/regular_file.txt" + mkdir -p "$HOME/.Trash/.hidden_dir" + mkdir -p "$HOME/.Trash/regular_dir" + + run bash <<'EOF' +set -euo pipefail +count=0 +while IFS= read -r -d '' item; do + ((count++)) || true + echo "FOUND: $(basename "$item")" +done < <(command find "$HOME/.Trash" -mindepth 1 -maxdepth 1 -print0 2> /dev/null || true) +echo "COUNT: $count" +EOF + + [ "$status" -eq 0 ] + [[ "$output" == *"COUNT: 5"* ]] + [[ "$output" == *"FOUND: .hidden_file"* ]] + [[ "$output" == *"FOUND: .DS_Store"* ]] + [[ "$output" == *"FOUND: .hidden_dir"* ]] + [[ "$output" == *"FOUND: regular_file.txt"* ]] +}