1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-11 22:19:00 +00:00

Optimize test reading version

This commit is contained in:
Tw93
2025-10-13 14:33:06 +08:00
parent db3b033fc0
commit 098d54b055
3 changed files with 21 additions and 12 deletions

View File

@@ -540,8 +540,7 @@ perform_cleanup() {
safe_clean ~/Library/Caches/com.apple.photoanalysisd "Photo analysis cache" 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.akd "Apple ID cache"
safe_clean ~/Library/Caches/com.apple.Safari/Webpage\ Previews/* "Safari webpage previews" safe_clean ~/Library/Caches/com.apple.Safari/Webpage\ Previews/* "Safari webpage previews"
safe_clean ~/Library/Mail/V*/MailData/Envelope\ Index* "Mail envelope index" # Mail envelope index and backup index are intentionally not cleaned (issue #32)
safe_clean ~/Library/Mail/V*/MailData/BackupTOC.plist "Mail backup index"
safe_clean ~/Library/Application\ Support/CloudDocs/session/db/* "iCloud session cache" safe_clean ~/Library/Application\ Support/CloudDocs/session/db/* "iCloud session cache"
end_section end_section
@@ -1116,6 +1115,7 @@ perform_cleanup() {
# Note: Disabled by default - container names may not match Bundle IDs # Note: Disabled by default - container names may not match Bundle IDs
MOLE_SPINNER_PREFIX=" " start_inline_spinner "Scanning orphaned containers..." MOLE_SPINNER_PREFIX=" " start_inline_spinner "Scanning orphaned containers..."
local containers_found=0 local containers_found=0
local containers_size_kb=0
if ls ~/Library/Containers/com.* > /dev/null 2>&1; then if ls ~/Library/Containers/com.* > /dev/null 2>&1; then
# Count potential orphaned containers but don't delete them # 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 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 if is_orphaned "$bundle_id" "$container_dir"; then
local size_kb=$(du -sk "$container_dir" 2> /dev/null | awk '{print $1}' || echo "0") local size_kb=$(du -sk "$container_dir" 2> /dev/null | awk '{print $1}' || echo "0")
if [[ "$size_kb" -gt 0 ]]; then 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++)) ((containers_found++))
((total_orphaned_kb += size_kb)) ((containers_size_kb += size_kb))
fi fi
fi fi
done done
fi fi
stop_inline_spinner 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 # Clean orphaned WebKit data
MOLE_SPINNER_PREFIX=" " start_inline_spinner "Scanning orphaned WebKit data..." MOLE_SPINNER_PREFIX=" " start_inline_spinner "Scanning orphaned WebKit data..."
@@ -1194,8 +1199,8 @@ perform_cleanup() {
stop_inline_spinner stop_inline_spinner
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Found $cookies_found orphaned cookie files" echo -e " ${GREEN}${ICON_SUCCESS}${NC} Found $cookies_found orphaned cookie files"
# Calculate total # Calculate total (exclude containers since they were not cleaned)
orphaned_count=$((cache_found + logs_found + states_found + containers_found + webkit_found + http_found + cookies_found)) orphaned_count=$((cache_found + logs_found + states_found + webkit_found + http_found + cookies_found))
if [[ $orphaned_count -gt 0 ]]; then if [[ $orphaned_count -gt 0 ]]; then
local orphaned_mb=$(echo "$total_orphaned_kb" | awk '{printf "%.1f", $1/1024}') local orphaned_mb=$(echo "$total_orphaned_kb" | awk '{printf "%.1f", $1/1024}')

View File

@@ -60,6 +60,7 @@ EOF
get_all_cache_items() { get_all_cache_items() {
# Format: "display_name|pattern|category" # Format: "display_name|pattern|category"
cat << 'EOF' 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 build cache (Android Studio, Gradle projects)|$HOME/.gradle/caches/*|ide_cache
Gradle daemon processes cache|$HOME/.gradle/daemon/*|ide_cache Gradle daemon processes cache|$HOME/.gradle/daemon/*|ide_cache
Xcode DerivedData (build outputs, indexes)|$HOME/Library/Developer/Xcode/DerivedData/*|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 for existing in "${CURRENT_WHITELIST_PATTERNS[@]}"; do
local existing_expanded="${existing/#\~/$HOME}" local existing_expanded="${existing/#\~/$HOME}"
if [[ "$check_pattern" == "$existing_expanded" ]]; then # Support both exact match and glob pattern match
return 0 # shellcheck disable=SC2053
fi if [[ "$check_pattern" == "$existing_expanded" ]] || [[ $check_pattern == $existing_expanded ]]; then
if [[ "$check_pattern" == "$existing_expanded" ]]; then
return 0 return 0
fi fi
done done

View File

@@ -4,6 +4,10 @@ setup_file() {
PROJECT_ROOT="$(cd "${BATS_TEST_DIRNAME}/.." && pwd)" PROJECT_ROOT="$(cd "${BATS_TEST_DIRNAME}/.." && pwd)"
export PROJECT_ROOT 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:-}" ORIGINAL_HOME="${HOME:-}"
export ORIGINAL_HOME export ORIGINAL_HOME
@@ -72,7 +76,7 @@ if [[ -n "$out" ]]; then
echo "Installer executed" echo "Installer executed"
INSTALLER INSTALLER
else else
echo 'VERSION="1.7.9"' echo "VERSION=\"$CURRENT_VERSION\""
fi fi
SCRIPT SCRIPT
chmod +x "$HOME/fake-bin/curl" chmod +x "$HOME/fake-bin/curl"