From 25f0fff91dcee41dc340a8a90428605477668d92 Mon Sep 17 00:00:00 2001 From: Tw93 Date: Thu, 18 Dec 2025 19:05:33 +0800 Subject: [PATCH] fix: Refine recent items clearing to target specific global lists and prevent accidental deletion --- lib/optimize/tasks.sh | 28 ++++++++++++++++++---------- mole | 2 +- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/optimize/tasks.sh b/lib/optimize/tasks.sh index 8054a32..68edd80 100644 --- a/lib/optimize/tasks.sh +++ b/lib/optimize/tasks.sh @@ -96,25 +96,33 @@ opt_log_cleanup() { opt_recent_items() { echo -e "${BLUE}${ICON_ARROW}${NC} Clearing recent items lists..." local shared_dir="$HOME/Library/Application Support/com.apple.sharedfilelist" + + # Target only the global recent item lists to avoid touching per-app/System Settings SFL files (Issue #136) + local -a recent_lists=( + "$shared_dir/com.apple.LSSharedFileList.RecentApplications.sfl2" + "$shared_dir/com.apple.LSSharedFileList.RecentDocuments.sfl2" + "$shared_dir/com.apple.LSSharedFileList.RecentServers.sfl2" + "$shared_dir/com.apple.LSSharedFileList.RecentHosts.sfl2" + "$shared_dir/com.apple.LSSharedFileList.RecentApplications.sfl" + "$shared_dir/com.apple.LSSharedFileList.RecentDocuments.sfl" + "$shared_dir/com.apple.LSSharedFileList.RecentServers.sfl" + "$shared_dir/com.apple.LSSharedFileList.RecentHosts.sfl" + ) + if [[ -d "$shared_dir" ]]; then - # Use safe removal with protection checks instead of find -delete - # This prevents accidental deletion of System Settings files local deleted=0 - while IFS= read -r -d '' sfl_file; do - # Check if file should be protected (System Settings, etc.) + for sfl_file in "${recent_lists[@]}"; do + # Skip missing files and any protected paths + [[ -e "$sfl_file" ]] || continue if should_protect_path "$sfl_file"; then continue fi if safe_remove "$sfl_file" true; then ((deleted++)) fi - done < <(command find "$shared_dir" -maxdepth 5 -name "*.sfl2" -type f -print0 2> /dev/null) + done - if [[ $deleted -gt 0 ]]; then - echo -e "${GREEN}${ICON_SUCCESS}${NC} Shared file lists cleared ($deleted files)" - else - echo -e "${GREEN}${ICON_SUCCESS}${NC} Shared file lists cleared" - fi + echo -e "${GREEN}${ICON_SUCCESS}${NC} Shared file lists cleared${deleted:+ ($deleted files)}" fi rm -f "$HOME/Library/Preferences/com.apple.recentitems.plist" 2> /dev/null || true diff --git a/mole b/mole index 3518a28..2b0340c 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.13.11" +VERSION="1.13.12" MOLE_TAGLINE="Deep clean and optimize your Mac." # Check TouchID configuration