1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-22 17:55:08 +00:00

refactor(clean): use assignment form for arithmetic increments in safe_clean

This commit is contained in:
tw93
2026-02-28 11:22:35 +08:00
parent 194e8ad29a
commit 75dc9f01dc
2 changed files with 23 additions and 23 deletions

View File

@@ -368,7 +368,7 @@ safe_clean() {
if should_protect_path "$path"; then if should_protect_path "$path"; then
skip=true skip=true
((skipped_count++)) skipped_count=$((skipped_count + 1))
log_operation "clean" "SKIPPED" "$path" "protected" log_operation "clean" "SKIPPED" "$path" "protected"
fi fi
@@ -376,7 +376,7 @@ safe_clean() {
if is_path_whitelisted "$path"; then if is_path_whitelisted "$path"; then
skip=true skip=true
((skipped_count++)) skipped_count=$((skipped_count + 1))
log_operation "clean" "SKIPPED" "$path" "whitelist" log_operation "clean" "SKIPPED" "$path" "whitelist"
fi fi
[[ "$skip" == "true" ]] && continue [[ "$skip" == "true" ]] && continue
@@ -410,7 +410,7 @@ safe_clean() {
fi fi
if [[ $skipped_count -gt 0 ]]; then if [[ $skipped_count -gt 0 ]]; then
((whitelist_skipped_count += skipped_count)) whitelist_skipped_count=$((whitelist_skipped_count + skipped_count))
fi fi
if [[ ${#existing_paths[@]} -eq 0 ]]; then if [[ ${#existing_paths[@]} -eq 0 ]]; then
@@ -474,7 +474,7 @@ safe_clean() {
echo "0 0" > "$temp_dir/result_${idx}" echo "0 0" > "$temp_dir/result_${idx}"
fi fi
((idx++)) idx=$((idx + 1))
if [[ $((idx % 20)) -eq 0 && "$show_spinner" == "true" && -t 1 ]]; then if [[ $((idx % 20)) -eq 0 && "$show_spinner" == "true" && -t 1 ]]; then
update_progress_if_needed "$idx" "${#existing_paths[@]}" last_progress_update 1 || true update_progress_if_needed "$idx" "${#existing_paths[@]}" last_progress_update 1 || true
last_progress_update=$(get_epoch_seconds) last_progress_update=$(get_epoch_seconds)
@@ -503,12 +503,12 @@ safe_clean() {
mv "$tmp_file" "$temp_dir/result_${idx}" 2> /dev/null || true mv "$tmp_file" "$temp_dir/result_${idx}" 2> /dev/null || true
) & ) &
pids+=($!) pids+=($!)
((idx++)) idx=$((idx + 1))
if ((${#pids[@]} >= MOLE_MAX_PARALLEL_JOBS)); then if ((${#pids[@]} >= MOLE_MAX_PARALLEL_JOBS)); then
wait "${pids[0]}" 2> /dev/null || true wait "${pids[0]}" 2> /dev/null || true
pids=("${pids[@]:1}") pids=("${pids[@]:1}")
((completed++)) completed=$((completed + 1))
if [[ "$show_spinner" == "true" && -t 1 ]]; then if [[ "$show_spinner" == "true" && -t 1 ]]; then
update_progress_if_needed "$completed" "$total_paths" last_progress_update 2 || true update_progress_if_needed "$completed" "$total_paths" last_progress_update 2 || true
@@ -520,7 +520,7 @@ safe_clean() {
if [[ ${#pids[@]} -gt 0 ]]; then if [[ ${#pids[@]} -gt 0 ]]; then
for pid in "${pids[@]}"; do for pid in "${pids[@]}"; do
wait "$pid" 2> /dev/null || true wait "$pid" 2> /dev/null || true
((completed++)) completed=$((completed + 1))
if [[ "$show_spinner" == "true" && -t 1 ]]; then if [[ "$show_spinner" == "true" && -t 1 ]]; then
update_progress_if_needed "$completed" "$total_paths" last_progress_update 2 || true update_progress_if_needed "$completed" "$total_paths" last_progress_update 2 || true
@@ -552,17 +552,17 @@ safe_clean() {
if [[ $removed -eq 1 ]]; then if [[ $removed -eq 1 ]]; then
if [[ "$size" -gt 0 ]]; then if [[ "$size" -gt 0 ]]; then
((total_size_kb += size)) total_size_kb=$((total_size_kb + size))
fi fi
((total_count += 1)) total_count=$((total_count + 1))
removed_any=1 removed_any=1
else else
if [[ -e "$path" && "$DRY_RUN" != "true" ]]; then if [[ -e "$path" && "$DRY_RUN" != "true" ]]; then
((removal_failed_count++)) removal_failed_count=$((removal_failed_count + 1))
fi fi
fi fi
fi fi
((idx++)) idx=$((idx + 1))
done done
fi fi
@@ -590,16 +590,16 @@ safe_clean() {
if [[ $removed -eq 1 ]]; then if [[ $removed -eq 1 ]]; then
if [[ "$size_kb" -gt 0 ]]; then if [[ "$size_kb" -gt 0 ]]; then
((total_size_kb += size_kb)) total_size_kb=$((total_size_kb + size_kb))
fi fi
((total_count += 1)) total_count=$((total_count + 1))
removed_any=1 removed_any=1
else else
if [[ -e "$path" && "$DRY_RUN" != "true" ]]; then if [[ -e "$path" && "$DRY_RUN" != "true" ]]; then
((removal_failed_count++)) removal_failed_count=$((removal_failed_count + 1))
fi fi
fi fi
((idx++)) idx=$((idx + 1))
done done
fi fi
fi fi
@@ -647,12 +647,12 @@ safe_clean() {
fi fi
[[ "$size" == "0" || -z "$size" ]] && { [[ "$size" == "0" || -z "$size" ]] && {
((idx++)) idx=$((idx + 1))
continue continue
} }
echo "$(dirname "$path")|$size|$path" >> "$paths_temp" echo "$(dirname "$path")|$size|$path" >> "$paths_temp"
((idx++)) idx=$((idx + 1))
done done
fi fi
@@ -692,9 +692,9 @@ safe_clean() {
else else
echo -e " ${GREEN}${ICON_SUCCESS}${NC} $label${NC}, ${GREEN}$size_human${NC}" echo -e " ${GREEN}${ICON_SUCCESS}${NC} $label${NC}, ${GREEN}$size_human${NC}"
fi fi
((files_cleaned += total_count)) files_cleaned=$((files_cleaned + total_count))
((total_size_cleaned += total_size_kb)) total_size_cleaned=$((total_size_cleaned + total_size_kb))
((total_items++)) total_items=$((total_items + 1))
note_activity note_activity
fi fi
@@ -870,9 +870,9 @@ perform_cleanup() {
done done
if [[ "$is_predefined" == "true" ]]; then if [[ "$is_predefined" == "true" ]]; then
((predefined_count++)) predefined_count=$((predefined_count + 1))
else else
((custom_count++)) custom_count=$((custom_count + 1))
fi fi
done done

View File

@@ -326,7 +326,7 @@ clean_orphaned_app_data() {
stop_section_spinner stop_section_spinner
if [[ $orphaned_count -gt 0 ]]; then if [[ $orphaned_count -gt 0 ]]; then
local orphaned_mb=$(echo "$total_orphaned_kb" | awk '{printf "%.1f", $1/1024}') local orphaned_mb=$(echo "$total_orphaned_kb" | awk '{printf "%.1f", $1/1024}')
echo " ${GREEN}${ICON_SUCCESS}${NC} Cleaned $orphaned_count items, about ${orphaned_mb}MB" echo -e " ${GREEN}${ICON_SUCCESS}${NC} Cleaned $orphaned_count items, about ${orphaned_mb}MB"
note_activity note_activity
fi fi
rm -f "$installed_bundles" rm -f "$installed_bundles"