mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 17:24:45 +00:00
Log cleaning does not take into account time
This commit is contained in:
@@ -11,20 +11,20 @@ clean_deep_system() {
|
|||||||
safe_sudo_find_delete "/Library/Caches" "*.tmp" "$MOLE_TEMP_FILE_AGE_DAYS" "f" || true
|
safe_sudo_find_delete "/Library/Caches" "*.tmp" "$MOLE_TEMP_FILE_AGE_DAYS" "f" || true
|
||||||
safe_sudo_find_delete "/Library/Caches" "*.log" "$MOLE_LOG_AGE_DAYS" "f" || true
|
safe_sudo_find_delete "/Library/Caches" "*.log" "$MOLE_LOG_AGE_DAYS" "f" || true
|
||||||
|
|
||||||
# Clean old temp files - use real paths (macOS /tmp is symlink to /private/tmp)
|
# Clean temp files - use real paths (macOS /tmp is symlink to /private/tmp)
|
||||||
local tmp_cleaned=0
|
local tmp_cleaned=0
|
||||||
safe_sudo_find_delete "/private/tmp" "*" "${MOLE_TEMP_FILE_AGE_DAYS}" "f" && tmp_cleaned=1 || true
|
safe_sudo_find_delete "/private/tmp" "*" "${MOLE_TEMP_FILE_AGE_DAYS}" "f" && tmp_cleaned=1 || true
|
||||||
safe_sudo_find_delete "/private/var/tmp" "*" "${MOLE_TEMP_FILE_AGE_DAYS}" "f" && tmp_cleaned=1 || true
|
safe_sudo_find_delete "/private/var/tmp" "*" "${MOLE_TEMP_FILE_AGE_DAYS}" "f" && tmp_cleaned=1 || true
|
||||||
[[ $tmp_cleaned -eq 1 ]] && log_success "Old system temp files (${MOLE_TEMP_FILE_AGE_DAYS}+ days)"
|
[[ $tmp_cleaned -eq 1 ]] && log_success "System temp files"
|
||||||
|
|
||||||
# Clean crash reports
|
# Clean crash reports
|
||||||
safe_sudo_find_delete "/Library/Logs/DiagnosticReports" "*" "$MOLE_CRASH_REPORT_AGE_DAYS" "f" || true
|
safe_sudo_find_delete "/Library/Logs/DiagnosticReports" "*" "$MOLE_CRASH_REPORT_AGE_DAYS" "f" || true
|
||||||
log_success "Old system crash reports (${MOLE_CRASH_REPORT_AGE_DAYS}+ days)"
|
log_success "System crash reports"
|
||||||
|
|
||||||
# Clean system logs - use real path (macOS /var is symlink to /private/var)
|
# Clean system logs - use real path (macOS /var is symlink to /private/var)
|
||||||
safe_sudo_find_delete "/private/var/log" "*.log" "$MOLE_LOG_AGE_DAYS" "f" || true
|
safe_sudo_find_delete "/private/var/log" "*.log" "$MOLE_LOG_AGE_DAYS" "f" || true
|
||||||
safe_sudo_find_delete "/private/var/log" "*.gz" "$MOLE_LOG_AGE_DAYS" "f" || true
|
safe_sudo_find_delete "/private/var/log" "*.gz" "$MOLE_LOG_AGE_DAYS" "f" || true
|
||||||
log_success "Old system logs (${MOLE_LOG_AGE_DAYS}+ days)"
|
log_success "System logs"
|
||||||
|
|
||||||
# Clean Library Updates safely - skip if SIP is enabled to avoid error messages
|
# Clean Library Updates safely - skip if SIP is enabled to avoid error messages
|
||||||
# SIP-protected files in /Library/Updates cannot be deleted even with sudo
|
# SIP-protected files in /Library/Updates cannot be deleted even with sudo
|
||||||
@@ -90,15 +90,15 @@ clean_deep_system() {
|
|||||||
|
|
||||||
[[ $code_sign_cleaned -gt 0 ]] && log_success "Browser code signature caches ($code_sign_cleaned items)"
|
[[ $code_sign_cleaned -gt 0 ]] && log_success "Browser code signature caches ($code_sign_cleaned items)"
|
||||||
|
|
||||||
# Clean system diagnostics logs (older than 30 days)
|
# Clean system diagnostics logs
|
||||||
safe_sudo_find_delete "/private/var/db/diagnostics/Special" "*" "$MOLE_LOG_AGE_DAYS" "f" || true
|
safe_sudo_find_delete "/private/var/db/diagnostics/Special" "*" "$MOLE_LOG_AGE_DAYS" "f" || true
|
||||||
safe_sudo_find_delete "/private/var/db/diagnostics/Persist" "*" "$MOLE_LOG_AGE_DAYS" "f" || true
|
safe_sudo_find_delete "/private/var/db/diagnostics/Persist" "*" "$MOLE_LOG_AGE_DAYS" "f" || true
|
||||||
safe_sudo_find_delete "/private/var/db/DiagnosticPipeline" "*" "$MOLE_LOG_AGE_DAYS" "f" || true
|
safe_sudo_find_delete "/private/var/db/DiagnosticPipeline" "*" "$MOLE_LOG_AGE_DAYS" "f" || true
|
||||||
log_success "Old system diagnostic logs (${MOLE_LOG_AGE_DAYS}+ days)"
|
log_success "System diagnostic logs"
|
||||||
|
|
||||||
# Clean power logs (older than 30 days)
|
# Clean power logs
|
||||||
safe_sudo_find_delete "/private/var/db/powerlog" "*" "$MOLE_LOG_AGE_DAYS" "f" || true
|
safe_sudo_find_delete "/private/var/db/powerlog" "*" "$MOLE_LOG_AGE_DAYS" "f" || true
|
||||||
log_success "Old power logs (${MOLE_LOG_AGE_DAYS}+ days)"
|
log_success "Power logs"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Clean Time Machine failed backups
|
# Clean Time Machine failed backups
|
||||||
|
|||||||
@@ -38,12 +38,12 @@ readonly ICON_NAV_LEFT="←"
|
|||||||
readonly ICON_NAV_RIGHT="→"
|
readonly ICON_NAV_RIGHT="→"
|
||||||
|
|
||||||
# Global configuration constants
|
# Global configuration constants
|
||||||
readonly MOLE_TEMP_FILE_AGE_DAYS=7 # Temp file cleanup threshold
|
readonly MOLE_TEMP_FILE_AGE_DAYS=0 # Temp file cleanup threshold (0 = all)
|
||||||
readonly MOLE_ORPHAN_AGE_DAYS=60 # Orphaned data threshold
|
readonly MOLE_ORPHAN_AGE_DAYS=60 # Orphaned data threshold
|
||||||
readonly MOLE_MAX_PARALLEL_JOBS=15 # Parallel job limit
|
readonly MOLE_MAX_PARALLEL_JOBS=15 # Parallel job limit
|
||||||
readonly MOLE_MAIL_DOWNLOADS_MIN_KB=5120 # Mail attachments size threshold (~5MB)
|
readonly MOLE_MAIL_DOWNLOADS_MIN_KB=5120 # Mail attachments size threshold (~5MB)
|
||||||
readonly MOLE_LOG_AGE_DAYS=30 # System log retention
|
readonly MOLE_LOG_AGE_DAYS=0 # System log retention (0 = all)
|
||||||
readonly MOLE_CRASH_REPORT_AGE_DAYS=30 # Crash report retention
|
readonly MOLE_CRASH_REPORT_AGE_DAYS=0 # Crash report retention (0 = all)
|
||||||
readonly MOLE_SAVED_STATE_AGE_DAYS=7 # App saved state retention
|
readonly MOLE_SAVED_STATE_AGE_DAYS=7 # App saved state retention
|
||||||
readonly MOLE_TM_BACKUP_SAFE_HOURS=48 # Time Machine failed backup safety window
|
readonly MOLE_TM_BACKUP_SAFE_HOURS=48 # Time Machine failed backup safety window
|
||||||
|
|
||||||
@@ -250,13 +250,22 @@ safe_find_delete() {
|
|||||||
|
|
||||||
# Execute find with safety limits
|
# Execute find with safety limits
|
||||||
debug_log "Finding in $base_dir: $pattern (age: ${age_days}d, type: $type_filter)"
|
debug_log "Finding in $base_dir: $pattern (age: ${age_days}d, type: $type_filter)"
|
||||||
|
|
||||||
command find "$base_dir" \
|
# When age_days is 0, delete all matching files without time restriction
|
||||||
-maxdepth 3 \
|
if [[ "$age_days" -eq 0 ]]; then
|
||||||
-name "$pattern" \
|
command find "$base_dir" \
|
||||||
-type "$type_filter" \
|
-maxdepth 3 \
|
||||||
-mtime "+$age_days" \
|
-name "$pattern" \
|
||||||
-delete 2> /dev/null || true
|
-type "$type_filter" \
|
||||||
|
-delete 2> /dev/null || true
|
||||||
|
else
|
||||||
|
command find "$base_dir" \
|
||||||
|
-maxdepth 3 \
|
||||||
|
-name "$pattern" \
|
||||||
|
-type "$type_filter" \
|
||||||
|
-mtime "+$age_days" \
|
||||||
|
-delete 2> /dev/null || true
|
||||||
|
fi
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@@ -288,13 +297,22 @@ safe_sudo_find_delete() {
|
|||||||
|
|
||||||
# Execute find with safety limits
|
# Execute find with safety limits
|
||||||
debug_log "Finding (sudo) in $base_dir: $pattern (age: ${age_days}d, type: $type_filter)"
|
debug_log "Finding (sudo) in $base_dir: $pattern (age: ${age_days}d, type: $type_filter)"
|
||||||
|
|
||||||
sudo command find "$base_dir" \
|
# When age_days is 0, delete all matching files without time restriction
|
||||||
-maxdepth 3 \
|
if [[ "$age_days" -eq 0 ]]; then
|
||||||
-name "$pattern" \
|
sudo command find "$base_dir" \
|
||||||
-type "$type_filter" \
|
-maxdepth 3 \
|
||||||
-mtime "+$age_days" \
|
-name "$pattern" \
|
||||||
-delete 2> /dev/null || true
|
-type "$type_filter" \
|
||||||
|
-delete 2> /dev/null || true
|
||||||
|
else
|
||||||
|
sudo command find "$base_dir" \
|
||||||
|
-maxdepth 3 \
|
||||||
|
-name "$pattern" \
|
||||||
|
-type "$type_filter" \
|
||||||
|
-mtime "+$age_days" \
|
||||||
|
-delete 2> /dev/null || true
|
||||||
|
fi
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user