mirror of
https://github.com/tw93/Mole.git
synced 2026-02-14 22:50:13 +00:00
Scan a large number of files for optimization
This commit is contained in:
12
bin/clean.sh
12
bin/clean.sh
@@ -323,6 +323,11 @@ safe_clean() {
|
|||||||
read -r size count < "$result_file" 2> /dev/null || true
|
read -r size count < "$result_file" 2> /dev/null || true
|
||||||
if [[ "$count" -gt 0 && "$size" -gt 0 ]]; then
|
if [[ "$count" -gt 0 && "$size" -gt 0 ]]; then
|
||||||
if [[ "$DRY_RUN" != "true" ]]; then
|
if [[ "$DRY_RUN" != "true" ]]; then
|
||||||
|
# Update spinner to show cleaning progress
|
||||||
|
if [[ -t 1 ]] && ((idx % 5 == 0)); then
|
||||||
|
stop_inline_spinner
|
||||||
|
MOLE_SPINNER_PREFIX=" " start_inline_spinner "Cleaning items ($idx/$total_paths)..."
|
||||||
|
fi
|
||||||
# Handle symbolic links separately (only remove the link, not the target)
|
# Handle symbolic links separately (only remove the link, not the target)
|
||||||
if [[ -L "$path" ]]; then
|
if [[ -L "$path" ]]; then
|
||||||
rm "$path" 2> /dev/null || true
|
rm "$path" 2> /dev/null || true
|
||||||
@@ -344,6 +349,7 @@ safe_clean() {
|
|||||||
local total_paths=${#existing_paths[@]}
|
local total_paths=${#existing_paths[@]}
|
||||||
if [[ -t 1 ]]; then MOLE_SPINNER_PREFIX=" " start_inline_spinner "Scanning $total_paths items..."; fi
|
if [[ -t 1 ]]; then MOLE_SPINNER_PREFIX=" " start_inline_spinner "Scanning $total_paths items..."; fi
|
||||||
|
|
||||||
|
local idx=0
|
||||||
for path in "${existing_paths[@]}"; do
|
for path in "${existing_paths[@]}"; do
|
||||||
local size_bytes
|
local size_bytes
|
||||||
size_bytes=$(get_path_size_kb "$path")
|
size_bytes=$(get_path_size_kb "$path")
|
||||||
@@ -351,6 +357,11 @@ safe_clean() {
|
|||||||
# Optimization: Skip expensive file counting
|
# Optimization: Skip expensive file counting
|
||||||
if [[ "$size_bytes" -gt 0 ]]; then
|
if [[ "$size_bytes" -gt 0 ]]; then
|
||||||
if [[ "$DRY_RUN" != "true" ]]; then
|
if [[ "$DRY_RUN" != "true" ]]; then
|
||||||
|
# Update spinner to show cleaning progress for slow operations
|
||||||
|
if [[ -t 1 ]]; then
|
||||||
|
stop_inline_spinner
|
||||||
|
MOLE_SPINNER_PREFIX=" " start_inline_spinner "Cleaning $description..."
|
||||||
|
fi
|
||||||
# Handle symbolic links separately (only remove the link, not the target)
|
# Handle symbolic links separately (only remove the link, not the target)
|
||||||
if [[ -L "$path" ]]; then
|
if [[ -L "$path" ]]; then
|
||||||
rm "$path" 2> /dev/null || true
|
rm "$path" 2> /dev/null || true
|
||||||
@@ -362,6 +373,7 @@ safe_clean() {
|
|||||||
((total_count += 1))
|
((total_count += 1))
|
||||||
removed_any=1
|
removed_any=1
|
||||||
fi
|
fi
|
||||||
|
((idx++))
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -97,7 +97,26 @@ clean_sandboxed_app_caches() {
|
|||||||
safe_clean ~/Library/Containers/com.apple.mediaanalysisd/Data/Library/Caches/* "Media analysis cache"
|
safe_clean ~/Library/Containers/com.apple.mediaanalysisd/Data/Library/Caches/* "Media analysis cache"
|
||||||
safe_clean ~/Library/Containers/com.apple.AppStore/Data/Library/Caches/* "App Store cache"
|
safe_clean ~/Library/Containers/com.apple.AppStore/Data/Library/Caches/* "App Store cache"
|
||||||
safe_clean ~/Library/Containers/com.apple.configurator.xpc.InternetService/Data/tmp/* "Apple Configurator temp files"
|
safe_clean ~/Library/Containers/com.apple.configurator.xpc.InternetService/Data/tmp/* "Apple Configurator temp files"
|
||||||
safe_clean ~/Library/Containers/*/Data/Library/Caches/* "Sandboxed app caches"
|
|
||||||
|
# Clean sandboxed app caches - iterate to avoid shell expansion hang
|
||||||
|
# Check container protection BEFORE expanding cache files to prevent
|
||||||
|
# redundant protection checks on each file (Issue #116)
|
||||||
|
local containers_dir="$HOME/Library/Containers"
|
||||||
|
[[ ! -d "$containers_dir" ]] && return 0
|
||||||
|
|
||||||
|
for container_dir in "$containers_dir"/*; do
|
||||||
|
[[ -d "$container_dir" ]] || continue
|
||||||
|
|
||||||
|
# Extract bundle ID and check protection status early
|
||||||
|
local bundle_id=$(basename "$container_dir")
|
||||||
|
if should_protect_data "$bundle_id"; then
|
||||||
|
debug_log "Protecting system container: $bundle_id"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
local cache_dir="$container_dir/Data/Library/Caches"
|
||||||
|
[[ -d "$cache_dir" ]] && safe_clean "$cache_dir"/* "Sandboxed app caches"
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# Clean browser caches (Safari, Chrome, Edge, Firefox, etc.)
|
# Clean browser caches (Safari, Chrome, Edge, Firefox, etc.)
|
||||||
@@ -166,20 +185,10 @@ clean_application_support_logs() {
|
|||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Clean log directories and cache patterns with iteration limit
|
# Clean log directories and cache patterns
|
||||||
# Reduced from 200 to 50 to prevent hanging on large directories
|
|
||||||
local iteration_count=0
|
|
||||||
local max_iterations=50
|
|
||||||
|
|
||||||
for app_dir in ~/Library/Application\ Support/*; do
|
for app_dir in ~/Library/Application\ Support/*; do
|
||||||
[[ -d "$app_dir" ]] || continue
|
[[ -d "$app_dir" ]] || continue
|
||||||
|
|
||||||
# Safety: limit iterations
|
|
||||||
((iteration_count++))
|
|
||||||
if [[ $iteration_count -gt $max_iterations ]]; then
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
|
|
||||||
app_name=$(basename "$app_dir")
|
app_name=$(basename "$app_dir")
|
||||||
|
|
||||||
# Skip system and protected apps (case-insensitive)
|
# Skip system and protected apps (case-insensitive)
|
||||||
|
|||||||
2
mole
2
mole
@@ -22,7 +22,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|||||||
source "$SCRIPT_DIR/lib/core/common.sh"
|
source "$SCRIPT_DIR/lib/core/common.sh"
|
||||||
|
|
||||||
# Version info
|
# Version info
|
||||||
VERSION="1.12.8"
|
VERSION="1.12.9"
|
||||||
MOLE_TAGLINE="can dig deep to clean your Mac."
|
MOLE_TAGLINE="can dig deep to clean your Mac."
|
||||||
|
|
||||||
# Check if Touch ID is already configured
|
# Check if Touch ID is already configured
|
||||||
|
|||||||
Reference in New Issue
Block a user