From 098d54b055845a86f0b5cdceda9146273efd8b45 Mon Sep 17 00:00:00 2001 From: Tw93 Date: Mon, 13 Oct 2025 14:33:06 +0800 Subject: [PATCH] Optimize test reading version --- bin/clean.sh | 19 ++++++++++++------- lib/whitelist_manager.sh | 8 ++++---- tests/update_remove.bats | 6 +++++- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/bin/clean.sh b/bin/clean.sh index 5504551..cb27aa1 100755 --- a/bin/clean.sh +++ b/bin/clean.sh @@ -540,8 +540,7 @@ perform_cleanup() { safe_clean ~/Library/Caches/com.apple.photoanalysisd "Photo analysis cache" safe_clean ~/Library/Caches/com.apple.akd "Apple ID cache" safe_clean ~/Library/Caches/com.apple.Safari/Webpage\ Previews/* "Safari webpage previews" - safe_clean ~/Library/Mail/V*/MailData/Envelope\ Index* "Mail envelope index" - safe_clean ~/Library/Mail/V*/MailData/BackupTOC.plist "Mail backup index" + # Mail envelope index and backup index are intentionally not cleaned (issue #32) safe_clean ~/Library/Application\ Support/CloudDocs/session/db/* "iCloud session cache" end_section @@ -1116,6 +1115,7 @@ perform_cleanup() { # Note: Disabled by default - container names may not match Bundle IDs MOLE_SPINNER_PREFIX=" " start_inline_spinner "Scanning orphaned containers..." local containers_found=0 + local containers_size_kb=0 if ls ~/Library/Containers/com.* > /dev/null 2>&1; then # Count potential orphaned containers but don't delete them for container_dir in ~/Library/Containers/com.* ~/Library/Containers/org.* ~/Library/Containers/net.* ~/Library/Containers/io.*; do @@ -1124,15 +1124,20 @@ perform_cleanup() { if is_orphaned "$bundle_id" "$container_dir"; then local size_kb=$(du -sk "$container_dir" 2> /dev/null | awk '{print $1}' || echo "0") if [[ "$size_kb" -gt 0 ]]; then - # DISABLED: safe_clean "$container_dir" "Orphaned container: $bundle_id" + # DISABLED: Not cleaned due to potential Bundle ID mismatch risk ((containers_found++)) - ((total_orphaned_kb += size_kb)) + ((containers_size_kb += size_kb)) fi fi done fi stop_inline_spinner - echo -e " ${GREEN}${ICON_SUCCESS}${NC} Skipped $containers_found potential orphaned containers" + if [[ $containers_found -gt 0 ]]; then + local containers_mb=$(echo "$containers_size_kb" | awk '{printf "%.1f", $1/1024}') + echo -e " ${GREEN}${ICON_SUCCESS}${NC} Skipped $containers_found potential orphaned containers (~${containers_mb}MB)" + else + echo -e " ${GREEN}${ICON_SUCCESS}${NC} No potential orphaned containers found" + fi # Clean orphaned WebKit data MOLE_SPINNER_PREFIX=" " start_inline_spinner "Scanning orphaned WebKit data..." @@ -1194,8 +1199,8 @@ perform_cleanup() { stop_inline_spinner echo -e " ${GREEN}${ICON_SUCCESS}${NC} Found $cookies_found orphaned cookie files" - # Calculate total - orphaned_count=$((cache_found + logs_found + states_found + containers_found + webkit_found + http_found + cookies_found)) + # Calculate total (exclude containers since they were not cleaned) + orphaned_count=$((cache_found + logs_found + states_found + webkit_found + http_found + cookies_found)) if [[ $orphaned_count -gt 0 ]]; then local orphaned_mb=$(echo "$total_orphaned_kb" | awk '{printf "%.1f", $1/1024}') diff --git a/lib/whitelist_manager.sh b/lib/whitelist_manager.sh index 18a5be3..6cb2fcc 100755 --- a/lib/whitelist_manager.sh +++ b/lib/whitelist_manager.sh @@ -60,6 +60,7 @@ EOF get_all_cache_items() { # Format: "display_name|pattern|category" cat << 'EOF' +Apple Mail cache|$HOME/Library/Caches/com.apple.mail/*|system_cache Gradle build cache (Android Studio, Gradle projects)|$HOME/.gradle/caches/*|ide_cache Gradle daemon processes cache|$HOME/.gradle/daemon/*|ide_cache Xcode DerivedData (build outputs, indexes)|$HOME/Library/Developer/Xcode/DerivedData/*|ide_cache @@ -159,10 +160,9 @@ is_whitelisted() { for existing in "${CURRENT_WHITELIST_PATTERNS[@]}"; do local existing_expanded="${existing/#\~/$HOME}" - if [[ "$check_pattern" == "$existing_expanded" ]]; then - return 0 - fi - if [[ "$check_pattern" == "$existing_expanded" ]]; then + # Support both exact match and glob pattern match + # shellcheck disable=SC2053 + if [[ "$check_pattern" == "$existing_expanded" ]] || [[ $check_pattern == $existing_expanded ]]; then return 0 fi done diff --git a/tests/update_remove.bats b/tests/update_remove.bats index 9c88a3e..93a8583 100644 --- a/tests/update_remove.bats +++ b/tests/update_remove.bats @@ -4,6 +4,10 @@ setup_file() { PROJECT_ROOT="$(cd "${BATS_TEST_DIRNAME}/.." && pwd)" export PROJECT_ROOT + # Read current version from mole file (single source of truth) + CURRENT_VERSION="$(grep '^VERSION=' "$PROJECT_ROOT/mole" | head -1 | sed 's/VERSION="\(.*\)"/\1/')" + export CURRENT_VERSION + ORIGINAL_HOME="${HOME:-}" export ORIGINAL_HOME @@ -72,7 +76,7 @@ if [[ -n "$out" ]]; then echo "Installer executed" INSTALLER else - echo 'VERSION="1.7.9"' + echo "VERSION=\"$CURRENT_VERSION\"" fi SCRIPT chmod +x "$HOME/fake-bin/curl"