1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-22 20:50:06 +00:00

refactor: Update shell arithmetic increment syntax from ((var++)) || true to var=$((var + 1)) across various scripts.

This commit is contained in:
tw93
2026-02-28 11:10:18 +08:00
parent 7d70889ad4
commit c19a0276b8
22 changed files with 141 additions and 141 deletions

View File

@@ -33,7 +33,7 @@ clean_ds_store_tree() {
local size
size=$(get_file_size "$ds_file")
total_bytes=$((total_bytes + size))
((file_count++)) || true
file_count=$((file_count + 1))
if [[ "$DRY_RUN" != "true" ]]; then
rm -f "$ds_file" 2> /dev/null || true
fi
@@ -53,9 +53,9 @@ clean_ds_store_tree() {
echo -e " ${GREEN}${ICON_SUCCESS}${NC} $label${NC}, ${GREEN}$file_count files, $size_human${NC}"
fi
local size_kb=$(((total_bytes + 1023) / 1024))
((files_cleaned += file_count)) || true
((total_size_cleaned += size_kb)) || true
((total_items++)) || true
files_cleaned=$((files_cleaned + file_count))
total_size_cleaned=$((total_size_cleaned + size_kb))
total_items=$((total_items + 1))
note_activity
fi
}
@@ -113,12 +113,12 @@ scan_installed_apps() {
local bundle_id=$(/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" "$plist_path" 2> /dev/null || echo "")
if [[ -n "$bundle_id" ]]; then
echo "$bundle_id"
((count++)) || true
count=$((count + 1))
fi
done
) > "$scan_tmp_dir/apps_${dir_idx}.txt" &
pids+=($!)
((dir_idx++)) || true
dir_idx=$((dir_idx + 1))
done
# Collect running apps and LaunchAgents to avoid false orphan cleanup.
(
@@ -300,7 +300,7 @@ clean_orphaned_app_data() {
fi
for match in "${matches[@]}"; do
[[ -e "$match" ]] || continue
((iteration_count++)) || true
iteration_count=$((iteration_count + 1))
if [[ $iteration_count -gt $MOLE_MAX_ORPHAN_ITERATIONS ]]; then
break
fi
@@ -314,8 +314,8 @@ clean_orphaned_app_data() {
continue
fi
if safe_clean "$match" "Orphaned $label: $bundle_id"; then
((orphaned_count++)) || true
((total_orphaned_kb += size_kb)) || true
orphaned_count=$((orphaned_count + 1))
total_orphaned_kb=$((total_orphaned_kb + size_kb))
fi
fi
done
@@ -430,8 +430,8 @@ clean_orphaned_system_services() {
orphaned_files+=("$plist")
local size_kb
size_kb=$(sudo du -skP "$plist" 2> /dev/null | awk '{print $1}' || echo "0")
((total_orphaned_kb += size_kb)) || true
((orphaned_count++)) || true
total_orphaned_kb=$((total_orphaned_kb + size_kb))
orphaned_count=$((orphaned_count + 1))
break
fi
done
@@ -461,8 +461,8 @@ clean_orphaned_system_services() {
orphaned_files+=("$plist")
local size_kb
size_kb=$(sudo du -skP "$plist" 2> /dev/null | awk '{print $1}' || echo "0")
((total_orphaned_kb += size_kb)) || true
((orphaned_count++)) || true
total_orphaned_kb=$((total_orphaned_kb + size_kb))
orphaned_count=$((orphaned_count + 1))
break
fi
done
@@ -491,8 +491,8 @@ clean_orphaned_system_services() {
orphaned_files+=("$helper")
local size_kb
size_kb=$(sudo du -skP "$helper" 2> /dev/null | awk '{print $1}' || echo "0")
((total_orphaned_kb += size_kb)) || true
((orphaned_count++)) || true
total_orphaned_kb=$((total_orphaned_kb + size_kb))
orphaned_count=$((orphaned_count + 1))
break
fi
done
@@ -673,7 +673,7 @@ clean_orphaned_launch_agents() {
if is_launch_item_orphaned "$plist"; then
local size_kb=$(get_path_size_kb "$plist")
orphaned_items+=("$bundle_id|$plist")
((total_orphaned_kb += size_kb)) || true
total_orphaned_kb=$((total_orphaned_kb + size_kb))
fi
done < <(find "$launch_agents_dir" -maxdepth 1 -name "*.plist" -print0 2> /dev/null)
@@ -696,7 +696,7 @@ clean_orphaned_launch_agents() {
IFS='|' read -r bundle_id plist_path <<< "$item"
if [[ "$is_dry_run" == "true" ]]; then
((dry_run_count++)) || true
dry_run_count=$((dry_run_count + 1))
log_operation "clean" "DRY_RUN" "$plist_path" "orphaned launch agent"
continue
fi
@@ -706,7 +706,7 @@ clean_orphaned_launch_agents() {
# Remove the plist file
if safe_remove "$plist_path" false; then
((removed_count++)) || true
removed_count=$((removed_count + 1))
log_operation "clean" "REMOVED" "$plist_path" "orphaned launch agent"
else
log_operation "clean" "FAILED" "$plist_path" "permission denied"

View File

@@ -208,7 +208,7 @@ clean_project_caches() {
break
fi
sleep 0.1
((grace_period++)) || true
grace_period=$((grace_period + 1))
done
if kill -0 "$pid" 2> /dev/null; then
kill -KILL "$pid" 2> /dev/null || true

View File

@@ -259,11 +259,11 @@ clean_xcode_documentation_cache() {
local entry
for entry in "${sorted_entries[@]}"; do
if [[ $idx -eq 0 ]]; then
((idx++)) || true
idx=$((idx + 1))
continue
fi
stale_entries+=("$entry")
((idx++)) || true
idx=$((idx + 1))
done
if [[ ${#stale_entries[@]} -eq 0 ]]; then
@@ -729,12 +729,12 @@ clean_dev_jetbrains_toolbox() {
local dir_path
for dir_path in "${sorted_dirs[@]}"; do
if [[ $idx -lt $keep_previous ]]; then
((idx++)) || true
idx=$((idx + 1))
continue
fi
safe_clean "$dir_path" "JetBrains Toolbox old IDE version"
note_activity
((idx++)) || true
idx=$((idx + 1))
done
done < <(command find "$product_dir" -mindepth 1 -maxdepth 1 -type d -name "ch-*" -print0 2> /dev/null)
done

View File

@@ -58,7 +58,7 @@ hint_get_path_size_kb_with_timeout() {
record_project_artifact_hint() {
local path="$1"
((PROJECT_ARTIFACT_HINT_COUNT++)) || true
PROJECT_ARTIFACT_HINT_COUNT=$((PROJECT_ARTIFACT_HINT_COUNT + 1))
if [[ ${#PROJECT_ARTIFACT_HINT_EXAMPLES[@]} -lt 2 ]]; then
PROJECT_ARTIFACT_HINT_EXAMPLES+=("${path/#$HOME/~}")
@@ -74,8 +74,8 @@ record_project_artifact_hint() {
local size_kb=""
if size_kb=$(hint_get_path_size_kb_with_timeout "$path" "$timeout_seconds"); then
if [[ "$size_kb" =~ ^[0-9]+$ ]]; then
((PROJECT_ARTIFACT_HINT_ESTIMATED_KB += size_kb)) || true
((PROJECT_ARTIFACT_HINT_ESTIMATE_SAMPLES++)) || true
PROJECT_ARTIFACT_HINT_ESTIMATED_KB=$((PROJECT_ARTIFACT_HINT_ESTIMATED_KB + size_kb))
PROJECT_ARTIFACT_HINT_ESTIMATE_SAMPLES=$((PROJECT_ARTIFACT_HINT_ESTIMATE_SAMPLES + 1))
else
PROJECT_ARTIFACT_HINT_ESTIMATE_PARTIAL=true
fi
@@ -140,8 +140,8 @@ probe_project_artifact_hints() {
local root_projects_scanned=0
if is_quick_purge_project_root "$root"; then
((scanned_projects++)) || true
((root_projects_scanned++)) || true
scanned_projects=$((scanned_projects + 1))
root_projects_scanned=$((root_projects_scanned + 1))
if [[ $scanned_projects -gt $max_projects ]]; then
PROJECT_ARTIFACT_HINT_TRUNCATED=true
stop_scan=true
@@ -175,8 +175,8 @@ probe_project_artifact_hints() {
break
fi
((scanned_projects++)) || true
((root_projects_scanned++)) || true
scanned_projects=$((scanned_projects + 1))
root_projects_scanned=$((root_projects_scanned + 1))
if [[ $scanned_projects -gt $max_projects ]]; then
PROJECT_ARTIFACT_HINT_TRUNCATED=true
stop_scan=true
@@ -206,7 +206,7 @@ probe_project_artifact_hints() {
;;
esac
((nested_count++)) || true
nested_count=$((nested_count + 1))
if [[ $nested_count -gt $max_nested_per_project ]]; then
break
fi

View File

@@ -640,7 +640,7 @@ select_purge_categories() {
for ((i = 0; i < total_items; i++)); do
if [[ ${selected[i]} == true ]]; then
selected_size=$((selected_size + ${sizes[i]:-0}))
((selected_count++)) || true
selected_count=$((selected_count + 1))
fi
done
@@ -728,9 +728,9 @@ select_purge_categories() {
local visible_count=$((total_items - top_index))
[[ $visible_count -gt $items_per_page ]] && visible_count=$items_per_page
if [[ $cursor_pos -lt $((visible_count - 1)) ]]; then
((cursor_pos++)) || true
cursor_pos=$((cursor_pos + 1))
elif [[ $((top_index + visible_count)) -lt $total_items ]]; then
((top_index++)) || true
top_index=$((top_index + 1))
fi
fi
}
@@ -1350,7 +1350,7 @@ clean_project_artifacts() {
[[ "$selected_size_kb" =~ ^[0-9]+$ ]] || selected_size_kb=0
selected_total_kb=$((selected_total_kb + selected_size_kb))
if [[ "${item_size_unknown_flags[idx]:-false}" == "true" ]]; then
((selected_unknown_count++)) || true
selected_unknown_count=$((selected_unknown_count + 1))
fi
done
@@ -1391,7 +1391,7 @@ clean_project_artifacts() {
if [[ ! -e "$item_path" ]]; then
local current_total=$(cat "$stats_dir/purge_stats" 2> /dev/null || echo "0")
echo "$((current_total + size_kb))" > "$stats_dir/purge_stats"
((cleaned_count++)) || true
cleaned_count=$((cleaned_count + 1))
fi
fi
if [[ -t 1 ]]; then

View File

@@ -86,7 +86,7 @@ clean_deep_system() {
continue
fi
if safe_sudo_remove "$item"; then
((updates_cleaned++)) || true
updates_cleaned=$((updates_cleaned + 1))
fi
done < <(find /Library/Updates -mindepth 1 -maxdepth 1 -print0 2> /dev/null || true)
stop_section_spinner
@@ -143,7 +143,7 @@ clean_deep_system() {
debug_log "Cleaning macOS installer: $app_name, $size_human, ${age_days} days old"
if safe_sudo_remove "$installer_app"; then
log_success "$app_name, $size_human"
((installer_cleaned++)) || true
installer_cleaned=$((installer_cleaned + 1))
fi
fi
done
@@ -153,7 +153,7 @@ clean_deep_system() {
local code_sign_cleaned=0
while IFS= read -r -d '' cache_dir; do
if safe_sudo_remove "$cache_dir"; then
((code_sign_cleaned++)) || true
code_sign_cleaned=$((code_sign_cleaned + 1))
fi
done < <(run_with_timeout 5 command find /private/var/folders -type d -name "*.code_sign_clone" -path "*/X/*" -print0 2> /dev/null || true)
stop_section_spinner
@@ -300,7 +300,7 @@ clean_time_machine_failed_backups() {
size_human=$(bytes_to_human "$((size_kb * 1024))")
if [[ "$DRY_RUN" == "true" ]]; then
echo -e " ${YELLOW}${ICON_DRY_RUN}${NC} Incomplete backup: $backup_name${NC}, ${YELLOW}$size_human dry${NC}"
((tm_cleaned++)) || true
tm_cleaned=$((tm_cleaned + 1))
note_activity
continue
fi
@@ -310,10 +310,10 @@ clean_time_machine_failed_backups() {
fi
if tmutil delete "$inprogress_file" 2> /dev/null; then
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Incomplete backup: $backup_name${NC}, ${GREEN}$size_human${NC}"
((tm_cleaned++)) || true
((files_cleaned++)) || true
((total_size_cleaned += size_kb)) || true
((total_items++)) || true
tm_cleaned=$((tm_cleaned + 1))
files_cleaned=$((files_cleaned + 1))
total_size_cleaned=$((total_size_cleaned + size_kb))
total_items=$((total_items + 1))
note_activity
else
echo -e " ${YELLOW}!${NC} Could not delete: $backup_name · try manually with sudo"
@@ -352,7 +352,7 @@ clean_time_machine_failed_backups() {
size_human=$(bytes_to_human "$((size_kb * 1024))")
if [[ "$DRY_RUN" == "true" ]]; then
echo -e " ${YELLOW}${ICON_DRY_RUN}${NC} Incomplete APFS backup in $bundle_name: $backup_name${NC}, ${YELLOW}$size_human dry${NC}"
((tm_cleaned++)) || true
tm_cleaned=$((tm_cleaned + 1))
note_activity
continue
fi
@@ -361,10 +361,10 @@ clean_time_machine_failed_backups() {
fi
if tmutil delete "$inprogress_file" 2> /dev/null; then
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Incomplete APFS backup in $bundle_name: $backup_name${NC}, ${GREEN}$size_human${NC}"
((tm_cleaned++)) || true
((files_cleaned++)) || true
((total_size_cleaned += size_kb)) || true
((total_items++)) || true
tm_cleaned=$((tm_cleaned + 1))
files_cleaned=$((files_cleaned + 1))
total_size_cleaned=$((total_size_cleaned + size_kb))
total_items=$((total_items + 1))
note_activity
else
echo -e " ${YELLOW}!${NC} Could not delete from bundle: $backup_name"

View File

@@ -23,7 +23,7 @@ clean_user_essentials() {
local cleaned_count=0
while IFS= read -r -d '' item; do
if safe_remove "$item" true; then
((cleaned_count++)) || true
cleaned_count=$((cleaned_count + 1))
fi
done < <(command find "$HOME/.Trash" -mindepth 1 -maxdepth 1 -print0 2> /dev/null || true)
if [[ $cleaned_count -gt 0 ]]; then
@@ -100,8 +100,8 @@ _clean_mail_downloads() {
local file_size_kb
file_size_kb=$(get_path_size_kb "$file_path")
if safe_remove "$file_path" true; then
((count++)) || true
((cleaned_kb += file_size_kb)) || true
count=$((count + 1))
cleaned_kb=$((cleaned_kb + file_size_kb))
fi
fi
done < <(command find "$target_path" -type f -mtime +"$mail_age_days" -print0 2> /dev/null || true)
@@ -171,7 +171,7 @@ clean_chrome_old_versions() {
size_kb=$(get_path_size_kb "$dir" || echo 0)
size_kb="${size_kb:-0}"
total_size=$((total_size + size_kb))
((cleaned_count++)) || true
cleaned_count=$((cleaned_count + 1))
cleaned_any=true
if [[ "$DRY_RUN" != "true" ]]; then
if has_sudo_session; then
@@ -191,9 +191,9 @@ clean_chrome_old_versions() {
else
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Chrome old versions${NC}, ${GREEN}${cleaned_count} dirs, $size_human${NC}"
fi
((files_cleaned += cleaned_count)) || true
((total_size_cleaned += total_size)) || true
((total_items++)) || true
files_cleaned=$((files_cleaned + cleaned_count))
total_size_cleaned=$((total_size_cleaned + total_size))
total_items=$((total_items + 1))
note_activity
fi
}
@@ -257,7 +257,7 @@ clean_edge_old_versions() {
size_kb=$(get_path_size_kb "$dir" || echo 0)
size_kb="${size_kb:-0}"
total_size=$((total_size + size_kb))
((cleaned_count++)) || true
cleaned_count=$((cleaned_count + 1))
cleaned_any=true
if [[ "$DRY_RUN" != "true" ]]; then
if has_sudo_session; then
@@ -277,9 +277,9 @@ clean_edge_old_versions() {
else
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Edge old versions${NC}, ${GREEN}${cleaned_count} dirs, $size_human${NC}"
fi
((files_cleaned += cleaned_count)) || true
((total_size_cleaned += total_size)) || true
((total_items++)) || true
files_cleaned=$((files_cleaned + cleaned_count))
total_size_cleaned=$((total_size_cleaned + total_size))
total_items=$((total_items + 1))
note_activity
fi
}
@@ -324,7 +324,7 @@ clean_edge_updater_old_versions() {
size_kb=$(get_path_size_kb "$dir" || echo 0)
size_kb="${size_kb:-0}"
total_size=$((total_size + size_kb))
((cleaned_count++)) || true
cleaned_count=$((cleaned_count + 1))
cleaned_any=true
if [[ "$DRY_RUN" != "true" ]]; then
safe_remove "$dir" true > /dev/null 2>&1 || true
@@ -339,9 +339,9 @@ clean_edge_updater_old_versions() {
else
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Edge updater old versions${NC}, ${GREEN}${cleaned_count} dirs, $size_human${NC}"
fi
((files_cleaned += cleaned_count)) || true
((total_size_cleaned += total_size)) || true
((total_items++)) || true
files_cleaned=$((files_cleaned + cleaned_count))
total_size_cleaned=$((total_size_cleaned + total_size))
total_items=$((total_items + 1))
note_activity
fi
}
@@ -484,9 +484,9 @@ clean_app_caches() {
else
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Sandboxed app caches${NC}, ${GREEN}$size_human${NC}"
fi
((files_cleaned += cleaned_count)) || true
((total_size_cleaned += total_size)) || true
((total_items++)) || true
files_cleaned=$((files_cleaned + cleaned_count))
total_size_cleaned=$((total_size_cleaned + total_size))
total_items=$((total_items + 1))
note_activity
fi
@@ -513,9 +513,9 @@ process_container_cache() {
if find "$cache_dir" -mindepth 1 -maxdepth 1 -print -quit 2> /dev/null | grep -q .; then
local size
size=$(get_path_size_kb "$cache_dir")
((total_size += size)) || true
total_size=$((total_size + size))
found_any=true
((cleaned_count++)) || true
cleaned_count=$((cleaned_count + 1))
if [[ "$DRY_RUN" != "true" ]]; then
local item
while IFS= read -r -d '' item; do
@@ -613,7 +613,7 @@ clean_group_container_caches() {
item_size=$(get_path_size_kb "$item" 2> /dev/null) || item_size=0
[[ "$item_size" =~ ^[0-9]+$ ]] || item_size=0
candidate_changed=true
((candidate_size_kb += item_size)) || true
candidate_size_kb=$((candidate_size_kb + item_size))
done
else
for item in "${items_to_clean[@]}"; do
@@ -622,14 +622,14 @@ clean_group_container_caches() {
[[ "$item_size" =~ ^[0-9]+$ ]] || item_size=0
if safe_remove "$item" true 2> /dev/null; then
candidate_changed=true
((candidate_size_kb += item_size)) || true
candidate_size_kb=$((candidate_size_kb + item_size))
fi
done
fi
if [[ "$candidate_changed" == "true" ]]; then
((total_size += candidate_size_kb)) || true
((cleaned_count++)) || true
total_size=$((total_size + candidate_size_kb))
cleaned_count=$((cleaned_count + 1))
found_any=true
fi
done
@@ -645,9 +645,9 @@ clean_group_container_caches() {
else
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Group Containers logs/caches${NC}, ${GREEN}$size_human${NC}"
fi
((files_cleaned += cleaned_count)) || true
((total_size_cleaned += total_size)) || true
((total_items++)) || true
files_cleaned=$((files_cleaned + cleaned_count))
total_size_cleaned=$((total_size_cleaned + total_size))
total_items=$((total_items + 1))
note_activity
fi
}
@@ -808,7 +808,7 @@ clean_application_support_logs() {
[[ -d "$app_dir" ]] || continue
local app_name
app_name=$(basename "$app_dir")
((app_count++)) || true
app_count=$((app_count + 1))
update_progress_if_needed "$app_count" "$total_apps" last_progress_update 1 || true
local app_name_lower
app_name_lower=$(echo "$app_name" | LC_ALL=C tr '[:upper:]' '[:lower:]')
@@ -834,12 +834,12 @@ clean_application_support_logs() {
while IFS= read -r -d '' item; do
[[ -e "$item" ]] || continue
item_found=true
((candidate_item_count++)) || true
candidate_item_count=$((candidate_item_count + 1))
if [[ ! -L "$item" && (-f "$item" || -d "$item") ]]; then
local item_size_bytes=""
if item_size_bytes=$(app_support_item_size_bytes "$item" "$size_timeout_seconds"); then
if [[ "$item_size_bytes" =~ ^[0-9]+$ ]]; then
((candidate_size_bytes += item_size_bytes)) || true
candidate_size_bytes=$((candidate_size_bytes + item_size_bytes))
else
candidate_size_partial=true
fi
@@ -865,9 +865,9 @@ clean_application_support_logs() {
fi
done < <(command find "$candidate" -mindepth 1 -maxdepth 1 -print0 2> /dev/null || true)
if [[ "$item_found" == "true" ]]; then
((total_size_bytes += candidate_size_bytes)) || true
total_size_bytes=$((total_size_bytes + candidate_size_bytes))
[[ "$candidate_size_partial" == "true" ]] && total_size_partial=true
((cleaned_count++)) || true
cleaned_count=$((cleaned_count + 1))
found_any=true
fi
fi
@@ -889,12 +889,12 @@ clean_application_support_logs() {
while IFS= read -r -d '' item; do
[[ -e "$item" ]] || continue
item_found=true
((candidate_item_count++)) || true
candidate_item_count=$((candidate_item_count + 1))
if [[ ! -L "$item" && (-f "$item" || -d "$item") ]]; then
local item_size_bytes=""
if item_size_bytes=$(app_support_item_size_bytes "$item" "$size_timeout_seconds"); then
if [[ "$item_size_bytes" =~ ^[0-9]+$ ]]; then
((candidate_size_bytes += item_size_bytes)) || true
candidate_size_bytes=$((candidate_size_bytes + item_size_bytes))
else
candidate_size_partial=true
fi
@@ -920,9 +920,9 @@ clean_application_support_logs() {
fi
done < <(command find "$candidate" -mindepth 1 -maxdepth 1 -print0 2> /dev/null || true)
if [[ "$item_found" == "true" ]]; then
((total_size_bytes += candidate_size_bytes)) || true
total_size_bytes=$((total_size_bytes + candidate_size_bytes))
[[ "$candidate_size_partial" == "true" ]] && total_size_partial=true
((cleaned_count++)) || true
cleaned_count=$((cleaned_count + 1))
found_any=true
fi
fi
@@ -951,9 +951,9 @@ clean_application_support_logs() {
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Application Support logs/caches${NC}, ${GREEN}$size_human${NC}"
fi
fi
((files_cleaned += cleaned_count)) || true
((total_size_cleaned += total_size_kb)) || true
((total_items++)) || true
files_cleaned=$((files_cleaned + cleaned_count))
total_size_cleaned=$((total_size_cleaned + total_size_kb))
total_items=$((total_items + 1))
note_activity
fi
}