mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 18:34:46 +00:00
More thoughtful consideration
This commit is contained in:
@@ -868,7 +868,6 @@ perform_cleanup() {
|
|||||||
clean_time_machine_failed_backups
|
clean_time_machine_failed_backups
|
||||||
end_section
|
end_section
|
||||||
|
|
||||||
|
|
||||||
# ===== Final summary =====
|
# ===== Final summary =====
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
|
|||||||
@@ -60,15 +60,15 @@ clean_deep_system() {
|
|||||||
if [[ -d "/macOS Install Data" ]]; then
|
if [[ -d "/macOS Install Data" ]]; then
|
||||||
local mtime=$(get_file_mtime "/macOS Install Data")
|
local mtime=$(get_file_mtime "/macOS Install Data")
|
||||||
local age_days=$((($(date +%s) - mtime) / 86400))
|
local age_days=$((($(date +%s) - mtime) / 86400))
|
||||||
|
|
||||||
debug_log "Found macOS Install Data (age: ${age_days} days)"
|
debug_log "Found macOS Install Data (age: ${age_days} days)"
|
||||||
|
|
||||||
if [[ $age_days -ge 30 ]]; then
|
if [[ $age_days -ge 30 ]]; then
|
||||||
local size_kb=$(get_path_size_kb "/macOS Install Data")
|
local size_kb=$(get_path_size_kb "/macOS Install Data")
|
||||||
if [[ -n "$size_kb" && "$size_kb" -gt 0 ]]; then
|
if [[ -n "$size_kb" && "$size_kb" -gt 0 ]]; then
|
||||||
local size_human=$(bytes_to_human "$((size_kb * 1024))")
|
local size_human=$(bytes_to_human "$((size_kb * 1024))")
|
||||||
debug_log "Cleaning macOS Install Data: $size_human (${age_days} days old)"
|
debug_log "Cleaning macOS Install Data: $size_human (${age_days} days old)"
|
||||||
|
|
||||||
if safe_sudo_remove "/macOS Install Data"; then
|
if safe_sudo_remove "/macOS Install Data"; then
|
||||||
log_success "macOS Install Data ($size_human)"
|
log_success "macOS Install Data ($size_human)"
|
||||||
fi
|
fi
|
||||||
@@ -86,8 +86,8 @@ clean_deep_system() {
|
|||||||
if safe_remove "$cache_dir" true; then
|
if safe_remove "$cache_dir" true; then
|
||||||
((code_sign_cleaned++))
|
((code_sign_cleaned++))
|
||||||
fi
|
fi
|
||||||
done < <(find /private/var/folders -type d -name "*.code_sign_clone" -path "*/X/*" -print0 2>/dev/null || true)
|
done < <(find /private/var/folders -type d -name "*.code_sign_clone" -path "*/X/*" -print0 2> /dev/null || true)
|
||||||
|
|
||||||
[[ $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
|
# Clean system diagnostics logs
|
||||||
|
|||||||
@@ -205,12 +205,12 @@ clean_application_support_logs() {
|
|||||||
# Direct path access is fast and won't cause performance issues
|
# Direct path access is fast and won't cause performance issues
|
||||||
# Add new containers here as users report them
|
# Add new containers here as users report them
|
||||||
local known_group_containers=(
|
local known_group_containers=(
|
||||||
"group.com.apple.contentdelivery" # Issue #104: Can accumulate 4GB+ in Library/Logs/Transporter
|
"group.com.apple.contentdelivery" # Issue #104: Can accumulate 4GB+ in Library/Logs/Transporter
|
||||||
)
|
)
|
||||||
|
|
||||||
for container in "${known_group_containers[@]}"; do
|
for container in "${known_group_containers[@]}"; do
|
||||||
local container_path="$HOME/Library/Group Containers/$container"
|
local container_path="$HOME/Library/Group Containers/$container"
|
||||||
|
|
||||||
# Check both direct Logs and Library/Logs patterns
|
# Check both direct Logs and Library/Logs patterns
|
||||||
if [[ -d "$container_path/Logs" ]]; then
|
if [[ -d "$container_path/Logs" ]]; then
|
||||||
debug_log "Scanning Group Container: $container/Logs"
|
debug_log "Scanning Group Container: $container/Logs"
|
||||||
|
|||||||
@@ -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=0 # Temp file cleanup threshold (0 = all)
|
readonly MOLE_TEMP_FILE_AGE_DAYS=7 # Temp file cleanup threshold
|
||||||
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=0 # System log retention (0 = all)
|
readonly MOLE_LOG_AGE_DAYS=7 # System log retention
|
||||||
readonly MOLE_CRASH_REPORT_AGE_DAYS=0 # Crash report retention (0 = all)
|
readonly MOLE_CRASH_REPORT_AGE_DAYS=7 # Crash report retention
|
||||||
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
|
||||||
|
|
||||||
@@ -248,19 +248,19 @@ safe_find_delete() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Execute find with safety limits
|
# Execute find with safety limits (maxdepth 5 covers most app cache structures)
|
||||||
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)"
|
||||||
|
|
||||||
# When age_days is 0, delete all matching files without time restriction
|
# When age_days is 0, delete all matching files without time restriction
|
||||||
if [[ "$age_days" -eq 0 ]]; then
|
if [[ "$age_days" -eq 0 ]]; then
|
||||||
command find "$base_dir" \
|
command find "$base_dir" \
|
||||||
-maxdepth 3 \
|
-maxdepth 5 \
|
||||||
-name "$pattern" \
|
-name "$pattern" \
|
||||||
-type "$type_filter" \
|
-type "$type_filter" \
|
||||||
-delete 2> /dev/null || true
|
-delete 2> /dev/null || true
|
||||||
else
|
else
|
||||||
command find "$base_dir" \
|
command find "$base_dir" \
|
||||||
-maxdepth 3 \
|
-maxdepth 5 \
|
||||||
-name "$pattern" \
|
-name "$pattern" \
|
||||||
-type "$type_filter" \
|
-type "$type_filter" \
|
||||||
-mtime "+$age_days" \
|
-mtime "+$age_days" \
|
||||||
@@ -295,19 +295,19 @@ safe_sudo_find_delete() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Execute find with safety limits
|
# Execute find with safety limits (maxdepth 5 covers most app cache structures)
|
||||||
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)"
|
||||||
|
|
||||||
# When age_days is 0, delete all matching files without time restriction
|
# When age_days is 0, delete all matching files without time restriction
|
||||||
if [[ "$age_days" -eq 0 ]]; then
|
if [[ "$age_days" -eq 0 ]]; then
|
||||||
sudo command find "$base_dir" \
|
sudo command find "$base_dir" \
|
||||||
-maxdepth 3 \
|
-maxdepth 5 \
|
||||||
-name "$pattern" \
|
-name "$pattern" \
|
||||||
-type "$type_filter" \
|
-type "$type_filter" \
|
||||||
-delete 2> /dev/null || true
|
-delete 2> /dev/null || true
|
||||||
else
|
else
|
||||||
sudo command find "$base_dir" \
|
sudo command find "$base_dir" \
|
||||||
-maxdepth 3 \
|
-maxdepth 5 \
|
||||||
-name "$pattern" \
|
-name "$pattern" \
|
||||||
-type "$type_filter" \
|
-type "$type_filter" \
|
||||||
-mtime "+$age_days" \
|
-mtime "+$age_days" \
|
||||||
@@ -587,7 +587,10 @@ run_with_timeout() {
|
|||||||
"$@" &
|
"$@" &
|
||||||
local cmd_pid=$!
|
local cmd_pid=$!
|
||||||
|
|
||||||
(sleep "$duration"; kill -TERM "$cmd_pid" 2> /dev/null || true) &
|
(
|
||||||
|
sleep "$duration"
|
||||||
|
kill -TERM "$cmd_pid" 2> /dev/null || true
|
||||||
|
) &
|
||||||
local killer_pid=$!
|
local killer_pid=$!
|
||||||
|
|
||||||
local exit_code
|
local exit_code
|
||||||
@@ -1188,7 +1191,7 @@ clean_tool_cache() {
|
|||||||
if [[ ${#cache_dirs[@]} -gt 0 ]]; then
|
if [[ ${#cache_dirs[@]} -gt 0 ]]; then
|
||||||
for dir in "${cache_dirs[@]}"; do
|
for dir in "${cache_dirs[@]}"; do
|
||||||
if [[ -d "$dir" ]]; then
|
if [[ -d "$dir" ]]; then
|
||||||
local dir_size=$(get_path_size_kb "$dir" 2>/dev/null || echo "0")
|
local dir_size=$(get_path_size_kb "$dir" 2> /dev/null || echo "0")
|
||||||
((size_before += dir_size))
|
((size_before += dir_size))
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user