From 42893381e3cfe18725de28896368cec7e1ffdaea Mon Sep 17 00:00:00 2001 From: NeedmeFordev <124189514+spider-yamet@users.noreply.github.com> Date: Wed, 11 Feb 2026 11:40:34 +0900 Subject: [PATCH] fix silent exit on permission denied during App State Cleanup (#440) --- lib/optimize/tasks.sh | 4 ++-- tests/clean_system_maintenance.bats | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/optimize/tasks.sh b/lib/optimize/tasks.sh index c213860..caf2c90 100644 --- a/lib/optimize/tasks.sh +++ b/lib/optimize/tasks.sh @@ -164,7 +164,7 @@ opt_cache_refresh() { if [[ "$size_kb" =~ ^[0-9]+$ ]]; then total_cache_size=$((total_cache_size + size_kb)) fi - safe_remove "$target_path" true > /dev/null 2>&1 + safe_remove "$target_path" true > /dev/null 2>&1 || true fi fi done @@ -195,7 +195,7 @@ opt_saved_state_cleanup() { if should_protect_path "$state_path"; then continue fi - safe_remove "$state_path" true > /dev/null 2>&1 + safe_remove "$state_path" true > /dev/null 2>&1 || true done < <(command find "$state_dir" -type d -name "*.savedState" -mtime "+$MOLE_SAVED_STATE_AGE_DAYS" -print0 2> /dev/null) fi diff --git a/tests/clean_system_maintenance.bats b/tests/clean_system_maintenance.bats index 46f52ed..bec4928 100644 --- a/tests/clean_system_maintenance.bats +++ b/tests/clean_system_maintenance.bats @@ -500,6 +500,23 @@ EOF [[ "$output" == *"App saved states optimized"* ]] } +@test "opt_saved_state_cleanup continues on permission denied (silent exit)" { + local state_dir="$HOME/Library/Saved Application State" + mkdir -p "$state_dir/com.example.old.savedState" + touch -t 202301010000 "$state_dir/com.example.old.savedState" 2>/dev/null || true + + run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc << 'EOF' +set -euo pipefail +source "$PROJECT_ROOT/lib/core/common.sh" +source "$PROJECT_ROOT/lib/optimize/tasks.sh" +safe_remove() { return 1; } +opt_saved_state_cleanup +EOF + + [ "$status" -eq 0 ] + [[ "$output" == *"App saved states optimized"* ]] +} + @test "opt_cache_refresh cleans Quick Look cache" { mkdir -p "$HOME/Library/Caches/com.apple.QuickLook.thumbnailcache" touch "$HOME/Library/Caches/com.apple.QuickLook.thumbnailcache/test.db"