mirror of
https://github.com/tw93/Mole.git
synced 2026-02-09 08:29:20 +00:00
Safety and Reliability Improvements
This commit is contained in:
@@ -32,7 +32,7 @@ clean_ds_store_tree() {
|
||||
)
|
||||
|
||||
# Build find command to avoid unbound array expansion with set -u
|
||||
local -a find_cmd=("find" "$target")
|
||||
local -a find_cmd=("command" "find" "$target")
|
||||
if [[ "$target" == "$HOME" ]]; then
|
||||
find_cmd+=("-maxdepth" "5")
|
||||
fi
|
||||
@@ -100,7 +100,7 @@ clean_orphaned_app_data() {
|
||||
|
||||
for app_dir in "${app_dirs[@]}"; do
|
||||
[[ -d "$app_dir" ]] || continue
|
||||
find "$app_dir" -name "*.app" -maxdepth 3 -type d 2> /dev/null | while IFS= read -r app_path; do
|
||||
command find "$app_dir" -name "*.app" -maxdepth 3 -type d 2> /dev/null | while IFS= read -r app_path; do
|
||||
local bundle_id
|
||||
bundle_id=$(defaults read "$app_path/Contents/Info.plist" CFBundleIdentifier 2> /dev/null || echo "")
|
||||
[[ -n "$bundle_id" ]] && echo "$bundle_id"
|
||||
|
||||
@@ -44,7 +44,7 @@ check_tcc_permissions() {
|
||||
# Trigger all TCC prompts upfront by accessing each directory
|
||||
# Using find -maxdepth 1 ensures we touch the directory without deep scanning
|
||||
for dir in "${tcc_dirs[@]}"; do
|
||||
[[ -d "$dir" ]] && find "$dir" -maxdepth 1 -type d > /dev/null 2>&1
|
||||
[[ -d "$dir" ]] && command find "$dir" -maxdepth 1 -type d > /dev/null 2>&1
|
||||
done
|
||||
|
||||
stop_inline_spinner
|
||||
@@ -94,7 +94,7 @@ clean_service_worker_cache() {
|
||||
fi
|
||||
cleaned_size=$((cleaned_size + size))
|
||||
fi
|
||||
done < <(find "$cache_path" -type d -depth 2 2> /dev/null)
|
||||
done < <(command find "$cache_path" -type d -depth 2 2> /dev/null)
|
||||
|
||||
if [[ $cleaned_size -gt 0 ]]; then
|
||||
local cleaned_mb=$((cleaned_size / 1024))
|
||||
@@ -120,7 +120,7 @@ clean_project_caches() {
|
||||
local nextjs_tmp_file
|
||||
nextjs_tmp_file=$(create_temp_file)
|
||||
(
|
||||
find "$HOME" -P -mount -type d -name ".next" -maxdepth 3 \
|
||||
command find "$HOME" -P -mount -type d -name ".next" -maxdepth 3 \
|
||||
-not -path "*/Library/*" \
|
||||
-not -path "*/.Trash/*" \
|
||||
-not -path "*/node_modules/*" \
|
||||
@@ -164,7 +164,7 @@ clean_project_caches() {
|
||||
local pycache_tmp_file
|
||||
pycache_tmp_file=$(create_temp_file)
|
||||
(
|
||||
find "$HOME" -P -mount -type d -name "__pycache__" -maxdepth 3 \
|
||||
command find "$HOME" -P -mount -type d -name "__pycache__" -maxdepth 3 \
|
||||
-not -path "*/Library/*" \
|
||||
-not -path "*/.Trash/*" \
|
||||
-not -path "*/node_modules/*" \
|
||||
|
||||
@@ -49,7 +49,7 @@ clean_broken_preferences() {
|
||||
((broken_count++))
|
||||
((total_size_kb += size_kb))
|
||||
fi
|
||||
done < <(find "$prefs_dir" -maxdepth 1 -name "*.plist" -type f 2> /dev/null || true)
|
||||
done < <(command find "$prefs_dir" -maxdepth 1 -name "*.plist" -type f 2> /dev/null || true)
|
||||
|
||||
# Check ByHost preferences
|
||||
local byhost_dir="$prefs_dir/ByHost"
|
||||
@@ -76,7 +76,7 @@ clean_broken_preferences() {
|
||||
((broken_count++))
|
||||
((total_size_kb += size_kb))
|
||||
fi
|
||||
done < <(find "$byhost_dir" -name "*.plist" -type f 2> /dev/null || true)
|
||||
done < <(command find "$byhost_dir" -name "*.plist" -type f 2> /dev/null || true)
|
||||
fi
|
||||
|
||||
if [[ -t 1 ]]; then
|
||||
@@ -153,7 +153,7 @@ clean_broken_login_items() {
|
||||
|
||||
((broken_count++))
|
||||
((total_size_kb += size_kb))
|
||||
done < <(find "$launch_agents_dir" -name "*.plist" -type f 2> /dev/null || true)
|
||||
done < <(command find "$launch_agents_dir" -name "*.plist" -type f 2> /dev/null || true)
|
||||
|
||||
if [[ -t 1 ]]; then
|
||||
stop_inline_spinner
|
||||
|
||||
@@ -13,12 +13,12 @@ clean_deep_system() {
|
||||
|
||||
# Clean old temp files
|
||||
local tmp_cleaned=0
|
||||
local tmp_count=$(sudo find /tmp -type f -mtime +"${MOLE_TEMP_FILE_AGE_DAYS}" 2> /dev/null | wc -l | tr -d ' ')
|
||||
local tmp_count=$(sudo command find /tmp -type f -mtime +"${MOLE_TEMP_FILE_AGE_DAYS}" 2> /dev/null | wc -l | tr -d ' ')
|
||||
if [[ "$tmp_count" -gt 0 ]]; then
|
||||
safe_sudo_find_delete "/tmp" "*" "${MOLE_TEMP_FILE_AGE_DAYS}" "f" || true
|
||||
tmp_cleaned=1
|
||||
fi
|
||||
local var_tmp_count=$(sudo find /var/tmp -type f -mtime +"${MOLE_TEMP_FILE_AGE_DAYS}" 2> /dev/null | wc -l | tr -d ' ')
|
||||
local var_tmp_count=$(sudo command find /var/tmp -type f -mtime +"${MOLE_TEMP_FILE_AGE_DAYS}" 2> /dev/null | wc -l | tr -d ' ')
|
||||
if [[ "$var_tmp_count" -gt 0 ]]; then
|
||||
safe_sudo_find_delete "/var/tmp" "*" "${MOLE_TEMP_FILE_AGE_DAYS}" "f" || true
|
||||
tmp_cleaned=1
|
||||
@@ -47,7 +47,7 @@ clean_deep_system() {
|
||||
while IFS= read -r -d '' item; do
|
||||
# Skip system-protected files (restricted flag)
|
||||
local item_flags
|
||||
item_flags=$(stat -f%Sf "$item" 2> /dev/null || echo "")
|
||||
item_flags=$(command stat -f%Sf "$item" 2> /dev/null || echo "")
|
||||
if [[ "$item_flags" == *"restricted"* ]]; then
|
||||
continue
|
||||
fi
|
||||
@@ -55,7 +55,7 @@ clean_deep_system() {
|
||||
if safe_sudo_remove "$item"; then
|
||||
((updates_cleaned++))
|
||||
fi
|
||||
done < <(find /Library/Updates -mindepth 1 -maxdepth 1 -print0 2> /dev/null)
|
||||
done < <(command find /Library/Updates -mindepth 1 -maxdepth 1 -print0 2> /dev/null)
|
||||
[[ $updates_cleaned -gt 0 ]] && log_success "System library updates"
|
||||
fi
|
||||
fi
|
||||
@@ -103,7 +103,7 @@ clean_time_machine_failed_backups() {
|
||||
fi
|
||||
fi
|
||||
|
||||
local fs_type=$(df -T "$volume" 2> /dev/null | tail -1 | awk '{print $2}')
|
||||
local fs_type=$(command df -T "$volume" 2> /dev/null | tail -1 | awk '{print $2}')
|
||||
case "$fs_type" in
|
||||
nfs | smbfs | afpfs | cifs | webdav) continue ;;
|
||||
esac
|
||||
@@ -150,7 +150,7 @@ clean_time_machine_failed_backups() {
|
||||
note_activity
|
||||
fi
|
||||
fi
|
||||
done < <(find "$backupdb_dir" -maxdepth 3 -type d \( -name "*.inProgress" -o -name "*.inprogress" \) 2> /dev/null || true)
|
||||
done < <(command find "$backupdb_dir" -maxdepth 3 -type d \( -name "*.inProgress" -o -name "*.inprogress" \) 2> /dev/null || true)
|
||||
fi
|
||||
|
||||
# APFS style backups (.backupbundle or .sparsebundle)
|
||||
@@ -200,7 +200,7 @@ clean_time_machine_failed_backups() {
|
||||
note_activity
|
||||
fi
|
||||
fi
|
||||
done < <(find "$mounted_path" -maxdepth 3 -type d \( -name "*.inProgress" -o -name "*.inprogress" \) 2> /dev/null || true)
|
||||
done < <(command find "$mounted_path" -maxdepth 3 -type d \( -name "*.inProgress" -o -name "*.inprogress" \) 2> /dev/null || true)
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
@@ -15,7 +15,7 @@ clean_user_essentials() {
|
||||
[[ -d "$volume" && -d "$volume/.Trashes" && -w "$volume" ]] || continue
|
||||
|
||||
# Skip network volumes
|
||||
local fs_type=$(df -T "$volume" 2> /dev/null | tail -1 | awk '{print $2}')
|
||||
local fs_type=$(command df -T "$volume" 2> /dev/null | tail -1 | awk '{print $2}')
|
||||
case "$fs_type" in
|
||||
nfs | smbfs | afpfs | cifs | webdav) continue ;;
|
||||
esac
|
||||
@@ -26,7 +26,7 @@ clean_user_essentials() {
|
||||
# Safely iterate and remove each item
|
||||
while IFS= read -r -d '' item; do
|
||||
safe_remove "$item" true || true
|
||||
done < <(find "$volume/.Trashes" -mindepth 1 -maxdepth 1 -print0 2> /dev/null)
|
||||
done < <(command find "$volume/.Trashes" -mindepth 1 -maxdepth 1 -print0 2> /dev/null)
|
||||
fi
|
||||
fi
|
||||
done
|
||||
@@ -65,7 +65,7 @@ clean_finder_metadata() {
|
||||
[[ -d "$volume" && -w "$volume" ]] || continue
|
||||
|
||||
local fs_type=""
|
||||
fs_type=$(df -T "$volume" 2> /dev/null | tail -1 | awk '{print $2}')
|
||||
fs_type=$(command df -T "$volume" 2> /dev/null | tail -1 | awk '{print $2}')
|
||||
case "$fs_type" in
|
||||
nfs | smbfs | afpfs | cifs | webdav) continue ;;
|
||||
esac
|
||||
@@ -150,7 +150,7 @@ clean_browsers() {
|
||||
[[ "$sw_path" == *"Arc"* ]] && browser_name="Arc"
|
||||
[[ "$profile_name" != "Default" ]] && browser_name="$browser_name ($profile_name)"
|
||||
clean_service_worker_cache "$browser_name" "$sw_path"
|
||||
done < <(find "$HOME/Library/Application Support/Google/Chrome" \
|
||||
done < <(command find "$HOME/Library/Application Support/Google/Chrome" \
|
||||
"$HOME/Library/Application Support/Microsoft Edge" \
|
||||
"$HOME/Library/Application Support/BraveSoftware/Brave-Browser" \
|
||||
"$HOME/Library/Application Support/Arc/User Data" \
|
||||
@@ -250,7 +250,7 @@ clean_application_support_logs() {
|
||||
local profile_name=$(basename "$profile_path")
|
||||
[[ "$profile_name" == "User Data" ]] && profile_name=$(basename "$(dirname "$profile_path")")
|
||||
clean_service_worker_cache "$app_name ($profile_name)" "$sw_cache"
|
||||
done < <(find "$app_dir" -maxdepth 4 -type d \( -name "CacheStorage" -o -name "ScriptCache" \) -path "*/Service Worker/*" 2> /dev/null || true)
|
||||
done < <(command find "$app_dir" -maxdepth 4 -type d \( -name "CacheStorage" -o -name "ScriptCache" \) -path "*/Service Worker/*" 2> /dev/null || true)
|
||||
|
||||
# Clean stale update downloads (older than 7 days)
|
||||
if [[ -d "$app_dir/update" ]] && ls "$app_dir/update" > /dev/null 2>&1; then
|
||||
@@ -259,7 +259,7 @@ clean_application_support_logs() {
|
||||
if [[ $dir_age_days -ge $MOLE_TEMP_FILE_AGE_DAYS ]]; then
|
||||
safe_clean "$update_dir" "Stale update: $app_name"
|
||||
fi
|
||||
done < <(find "$app_dir/update" -mindepth 1 -maxdepth 1 -type d 2> /dev/null || true)
|
||||
done < <(command find "$app_dir/update" -mindepth 1 -maxdepth 1 -type d 2> /dev/null || true)
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -268,17 +268,17 @@ clean_application_support_logs() {
|
||||
while IFS= read -r logs_dir; do
|
||||
local container_name=$(basename "$(dirname "$logs_dir")")
|
||||
safe_clean "$logs_dir"/* "Group container logs: $container_name"
|
||||
done < <(find "$HOME/Library/Group Containers" -maxdepth 2 -type d -name "Logs" 2> /dev/null || true)
|
||||
done < <(command find "$HOME/Library/Group Containers" -maxdepth 2 -type d -name "Logs" 2> /dev/null || true)
|
||||
fi
|
||||
}
|
||||
|
||||
# Check and show iOS device backup info
|
||||
check_ios_device_backups() {
|
||||
local backup_dir="$HOME/Library/Application Support/MobileSync/Backup"
|
||||
if [[ -d "$backup_dir" ]] && find "$backup_dir" -mindepth 1 -maxdepth 1 | read -r _; then
|
||||
if [[ -d "$backup_dir" ]] && command find "$backup_dir" -mindepth 1 -maxdepth 1 | read -r _; then
|
||||
local backup_kb=$(get_path_size_kb "$backup_dir")
|
||||
if [[ -n "${backup_kb:-}" && "$backup_kb" -gt 102400 ]]; then
|
||||
local backup_human=$(du -sh "$backup_dir" 2> /dev/null | awk '{print $1}')
|
||||
local backup_human=$(command du -sh "$backup_dir" 2> /dev/null | awk '{print $1}')
|
||||
note_activity
|
||||
echo -e " Found ${GREEN}${backup_human}${NC} iOS backups"
|
||||
echo -e " You can delete them manually: ${backup_dir}"
|
||||
|
||||
Reference in New Issue
Block a user