mirror of
https://github.com/tw93/Mole.git
synced 2026-03-22 17:55:08 +00:00
fix: tighten orphan cleanup retention windows
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
# Application Data Cleanup Module
|
||||
set -euo pipefail
|
||||
|
||||
readonly ORPHAN_AGE_THRESHOLD=${ORPHAN_AGE_THRESHOLD:-${MOLE_ORPHAN_AGE_DAYS:-60}}
|
||||
readonly ORPHAN_AGE_THRESHOLD=${ORPHAN_AGE_THRESHOLD:-${MOLE_ORPHAN_AGE_DAYS:-30}}
|
||||
readonly CLAUDE_VM_ORPHAN_AGE_THRESHOLD=${MOLE_CLAUDE_VM_ORPHAN_AGE_DAYS:-7}
|
||||
# Args: $1=target_dir, $2=label
|
||||
clean_ds_store_tree() {
|
||||
local target="$1"
|
||||
@@ -59,7 +60,7 @@ clean_ds_store_tree() {
|
||||
note_activity
|
||||
fi
|
||||
}
|
||||
# Orphaned app data (60+ days inactive). Env: ORPHAN_AGE_THRESHOLD, DRY_RUN
|
||||
# Orphaned app data (30+ days inactive). Env: ORPHAN_AGE_THRESHOLD, DRY_RUN
|
||||
# Usage: scan_installed_apps "output_file"
|
||||
scan_installed_apps() {
|
||||
local installed_bundles="$1"
|
||||
@@ -201,13 +202,13 @@ is_bundle_orphaned() {
|
||||
;;
|
||||
esac
|
||||
|
||||
# 5. Fast path: 60-day modification check (stat call, fast)
|
||||
# 5. Fast path: 30-day modification check (stat call, fast)
|
||||
if [[ -e "$directory_path" ]]; then
|
||||
local last_modified_epoch=$(get_file_mtime "$directory_path")
|
||||
local current_epoch
|
||||
current_epoch=$(get_epoch_seconds)
|
||||
local days_since_modified=$(((current_epoch - last_modified_epoch) / 86400))
|
||||
if [[ $days_since_modified -lt ${ORPHAN_AGE_THRESHOLD:-60} ]]; then
|
||||
if [[ $days_since_modified -lt ${ORPHAN_AGE_THRESHOLD:-30} ]]; then
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
@@ -267,7 +268,7 @@ is_claude_vm_bundle_orphaned() {
|
||||
local current_epoch
|
||||
current_epoch=$(get_epoch_seconds)
|
||||
local days_since_modified=$(((current_epoch - last_modified_epoch) / 86400))
|
||||
if [[ $days_since_modified -lt ${ORPHAN_AGE_THRESHOLD:-60} ]]; then
|
||||
if [[ $days_since_modified -lt ${CLAUDE_VM_ORPHAN_AGE_THRESHOLD:-7} ]]; then
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -68,7 +68,7 @@ get_lsregister_path() {
|
||||
# Global Configuration Constants
|
||||
# ============================================================================
|
||||
readonly MOLE_TEMP_FILE_AGE_DAYS=7 # Temp file retention (days)
|
||||
readonly MOLE_ORPHAN_AGE_DAYS=60 # Orphaned data retention (days)
|
||||
readonly MOLE_ORPHAN_AGE_DAYS=30 # Orphaned data retention (days)
|
||||
readonly MOLE_MAX_PARALLEL_JOBS=15 # Parallel job limit
|
||||
readonly MOLE_MAIL_DOWNLOADS_MIN_KB=5120 # Mail attachment size threshold
|
||||
readonly MOLE_MAIL_AGE_DAYS=30 # Mail attachment retention (days)
|
||||
|
||||
@@ -60,7 +60,7 @@ EOF
|
||||
}
|
||||
|
||||
@test "is_bundle_orphaned returns true for old uninstalled bundle" {
|
||||
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" ORPHAN_AGE_THRESHOLD=60 bash --noprofile --norc <<'EOF'
|
||||
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" ORPHAN_AGE_THRESHOLD=30 bash --noprofile --norc <<'EOF'
|
||||
set -euo pipefail
|
||||
source "$PROJECT_ROOT/lib/core/common.sh"
|
||||
source "$PROJECT_ROOT/lib/clean/apps.sh"
|
||||
@@ -116,12 +116,12 @@ safe_clean() {
|
||||
# Create required Library structure for permission check
|
||||
mkdir -p "$HOME/Library/Caches"
|
||||
|
||||
# Create test structure with spaces in path (old modification time: 61 days ago)
|
||||
# Create test structure with spaces in path (old modification time: 31 days ago)
|
||||
mkdir -p "$HOME/Library/Saved Application State/com.test.orphan.savedState"
|
||||
# Create a file with some content so directory size > 0
|
||||
echo "test data" > "$HOME/Library/Saved Application State/com.test.orphan.savedState/data.plist"
|
||||
# Set modification time to 61 days ago (older than 60-day threshold)
|
||||
touch -t "$(date -v-61d +%Y%m%d%H%M.%S 2>/dev/null || date -d '61 days ago' +%Y%m%d%H%M.%S)" "$HOME/Library/Saved Application State/com.test.orphan.savedState" 2>/dev/null || true
|
||||
# Set modification time to 31 days ago (older than 30-day threshold)
|
||||
touch -t "$(date -v-31d +%Y%m%d%H%M.%S 2>/dev/null || date -d '31 days ago' +%Y%m%d%H%M.%S)" "$HOME/Library/Saved Application State/com.test.orphan.savedState" 2>/dev/null || true
|
||||
|
||||
# Disable spinner for test
|
||||
start_section_spinner() { :; }
|
||||
@@ -165,15 +165,15 @@ run_with_timeout() { shift; "$@"; }
|
||||
# Create required Library structure for permission check
|
||||
mkdir -p "$HOME/Library/Caches"
|
||||
|
||||
# Create test files (old modification time: 61 days ago)
|
||||
# Create test files (old modification time: 31 days ago)
|
||||
mkdir -p "$HOME/Library/Caches/com.test.orphan1"
|
||||
mkdir -p "$HOME/Library/Caches/com.test.orphan2"
|
||||
# Create files with content so size > 0
|
||||
echo "data1" > "$HOME/Library/Caches/com.test.orphan1/data"
|
||||
echo "data2" > "$HOME/Library/Caches/com.test.orphan2/data"
|
||||
# Set modification time to 61 days ago
|
||||
touch -t "$(date -v-61d +%Y%m%d%H%M.%S 2>/dev/null || date -d '61 days ago' +%Y%m%d%H%M.%S)" "$HOME/Library/Caches/com.test.orphan1" 2>/dev/null || true
|
||||
touch -t "$(date -v-61d +%Y%m%d%H%M.%S 2>/dev/null || date -d '61 days ago' +%Y%m%d%H%M.%S)" "$HOME/Library/Caches/com.test.orphan2" 2>/dev/null || true
|
||||
# Set modification time to 31 days ago
|
||||
touch -t "$(date -v-31d +%Y%m%d%H%M.%S 2>/dev/null || date -d '31 days ago' +%Y%m%d%H%M.%S)" "$HOME/Library/Caches/com.test.orphan1" 2>/dev/null || true
|
||||
touch -t "$(date -v-31d +%Y%m%d%H%M.%S 2>/dev/null || date -d '31 days ago' +%Y%m%d%H%M.%S)" "$HOME/Library/Caches/com.test.orphan2" 2>/dev/null || true
|
||||
|
||||
# Mock safe_clean to fail on first item, succeed on second
|
||||
safe_clean() {
|
||||
|
||||
Reference in New Issue
Block a user