1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-04 09:46:44 +00:00

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.
This commit is contained in:
dekran
2026-01-31 16:37:22 +07:00
committed by GitHub
parent b8e15b1c16
commit dcac6a3391
3 changed files with 29 additions and 4 deletions

View File

@@ -150,4 +150,3 @@ func TestLargeFileHeap(t *testing.T) {
}
})
}

View File

@@ -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"

View File

@@ -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"* ]]
}