From 36c993ec1c3acf7d5b64d7b5c41e556dee81eb58 Mon Sep 17 00:00:00 2001 From: Tw93 Date: Thu, 4 Dec 2025 17:52:19 +0800 Subject: [PATCH] Fix the system update check problem --- bin/clean.sh | 23 +++++++++++++---------- lib/core/common.sh | 16 ++++++++-------- lib/manage/update.sh | 14 +++++++++----- mole | 2 +- 4 files changed, 31 insertions(+), 24 deletions(-) diff --git a/bin/clean.sh b/bin/clean.sh index c7cac31..bd50259 100755 --- a/bin/clean.sh +++ b/bin/clean.sh @@ -277,7 +277,7 @@ safe_clean() { local count # Quick file count - limit for performance if [[ "$size" -gt 0 ]]; then - count=$(find "$path" -type f 2>/dev/null | head -1000 | wc -l | tr -d ' ') + count=$(find "$path" -type f 2> /dev/null | head -1000 | wc -l | tr -d ' ') [[ -z "$count" || ! "$count" =~ ^[0-9]+$ ]] && count=0 else count=0 @@ -343,7 +343,7 @@ safe_clean() { [[ -z "$size_bytes" || ! "$size_bytes" =~ ^[0-9]+$ ]] && size_bytes=0 # Quick file count for display - limit for performance if [[ "$size_bytes" -gt 0 ]]; then - count=$(find "$path" -type f 2>/dev/null | head -1000 | wc -l | tr -d ' ') + count=$(find "$path" -type f 2> /dev/null | head -1000 | wc -l | tr -d ' ') [[ -z "$count" || ! "$count" =~ ^[0-9]+$ ]] && count=0 else count=0 @@ -392,13 +392,16 @@ safe_clean() { # Get size from result file if it exists (parallel processing with temp_dir) if [[ -n "${temp_dir:-}" && -f "$temp_dir/result_${idx}" ]]; then - read -r size count < "$temp_dir/result_${idx}" 2>/dev/null || true + read -r size count < "$temp_dir/result_${idx}" 2> /dev/null || true else # Get size directly (small batch processing or no temp_dir) - size=$(get_path_size_kb "$path" 2>/dev/null || echo "0") + size=$(get_path_size_kb "$path" 2> /dev/null || echo "0") fi - [[ "$size" == "0" || -z "$size" ]] && { ((idx++)); continue; } + [[ "$size" == "0" || -z "$size" ]] && { + ((idx++)) + continue + } # Write parent|size|path to temp file echo "$(dirname "$path")|$size|$path" >> "$paths_temp" @@ -687,18 +690,18 @@ perform_cleanup() { # Scan for .app bundles - optimized with PlistBuddy and xargs for search_path in "${search_paths[@]}"; do [[ -d "$search_path" ]] || continue - find "$search_path" -maxdepth 3 -name "Info.plist" -path "*/Contents/Info.plist" 2>/dev/null | \ - xargs -I {} /usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" {} 2>/dev/null | \ + find "$search_path" -maxdepth 3 -name "Info.plist" -path "*/Contents/Info.plist" 2> /dev/null | + xargs -I {} /usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" {} 2> /dev/null | grep -v "^$" >> "$installed_bundles" || true done # Get running applications - no timeout needed for fast osascript - osascript -e 'tell application "System Events" to get bundle identifier of every application process' 2>/dev/null | \ + osascript -e 'tell application "System Events" to get bundle identifier of every application process' 2> /dev/null | tr ',' '\n' | sed -e 's/^ *//;s/ *$//' -e '/^$/d' >> "$installed_bundles" || true # Get LaunchAgents - fast operation, no timeout needed - find ~/Library/LaunchAgents /Library/LaunchAgents -name "*.plist" -type f 2>/dev/null | \ - xargs -I {} basename {} .plist >> "$installed_bundles" 2>/dev/null || true + find ~/Library/LaunchAgents /Library/LaunchAgents -name "*.plist" -type f 2> /dev/null | + xargs -I {} basename {} .plist >> "$installed_bundles" 2> /dev/null || true # Deduplicate sort -u "$installed_bundles" -o "$installed_bundles" diff --git a/lib/core/common.sh b/lib/core/common.sh index a5963d2..927f1c7 100755 --- a/lib/core/common.sh +++ b/lib/core/common.sh @@ -553,23 +553,23 @@ run_with_timeout() { "$@" & local cmd_pid=$! - + # More efficient wait: use wait with timeout in subshell ( sleep "$duration" & local timer_pid=$! - wait "$cmd_pid" 2>/dev/null && kill "$timer_pid" 2>/dev/null && exit 0 - kill -TERM "$cmd_pid" 2>/dev/null || true + wait "$cmd_pid" 2> /dev/null && kill "$timer_pid" 2> /dev/null && exit 0 + kill -TERM "$cmd_pid" 2> /dev/null || true sleep 0.5 - kill -KILL "$cmd_pid" 2>/dev/null || true + kill -KILL "$cmd_pid" 2> /dev/null || true exit 124 ) & local watcher_pid=$! - - wait "$cmd_pid" 2>/dev/null + + wait "$cmd_pid" 2> /dev/null local exit_code=$? - kill "$watcher_pid" 2>/dev/null || true - wait "$watcher_pid" 2>/dev/null || true + kill "$watcher_pid" 2> /dev/null || true + wait "$watcher_pid" 2> /dev/null || true return $exit_code } diff --git a/lib/manage/update.sh b/lib/manage/update.sh index 90d6bd8..00ae1da 100644 --- a/lib/manage/update.sh +++ b/lib/manage/update.sh @@ -220,7 +220,7 @@ perform_updates() { # Check sudo access if ! has_sudo_session; then if ! ensure_sudo_session "Software updates require admin access"; then - echo -e "${YELLOW}${ICON_WARNING}${NC} Skipping App Store updates (admin authentication required)" + echo -e "${YELLOW}☻${NC} App Store updates available — update via System Settings" echo "" ((total_count--)) if [[ -n "${MACOS_UPDATE_AVAILABLE:-}" && "${MACOS_UPDATE_AVAILABLE}" == "true" ]]; then @@ -237,8 +237,9 @@ perform_updates() { # Update macOS if [[ -n "${MACOS_UPDATE_AVAILABLE:-}" && "${MACOS_UPDATE_AVAILABLE}" == "true" && "$macos_handled_via_appstore" != "true" ]]; then if ! has_sudo_session; then - echo -e "${YELLOW}${ICON_WARNING}${NC} Skipping macOS updates (admin authentication required)" + echo -e "${YELLOW}☻${NC} macOS updates available — update via System Settings" echo "" + ((total_count--)) else _perform_macos_update fi @@ -258,15 +259,18 @@ perform_updates() { fi # Summary - if [[ $updated_count -eq $total_count && $total_count -gt 0 ]]; then + if [[ $total_count -eq 0 ]]; then + echo -e "${GRAY}No updates to perform${NC}" + return 0 + elif [[ $updated_count -eq $total_count ]]; then echo -e "${GREEN}All updates completed (${updated_count}/${total_count})${NC}" return 0 elif [[ $updated_count -gt 0 ]]; then echo -e "${YELLOW}Partial updates completed (${updated_count}/${total_count})${NC}" - return 1 + return 0 else echo -e "${RED}No updates were completed${NC}" - return 1 + return 0 fi } diff --git a/mole b/mole index 4e48f12..0277fa8 100755 --- a/mole +++ b/mole @@ -22,7 +22,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "$SCRIPT_DIR/lib/core/common.sh" # Version info -VERSION="1.11.22" +VERSION="1.11.23" MOLE_TAGLINE="can dig deep to clean your Mac." # Check if Touch ID is already configured