1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-23 21:35:06 +00:00

fix: keep dry-run yellow and align clean output colors

Keep dry-run previews yellow while reusing the 1 GiB threshold for actual cleanup results across clean modules. Add regression coverage for the shared color helper and DS_Store cleanup output.
This commit is contained in:
Tw93
2026-03-23 17:53:02 +08:00
parent 4b82b4aa70
commit 5df81a2314
8 changed files with 105 additions and 27 deletions

View File

@@ -48,12 +48,14 @@ clean_ds_store_tree() {
if [[ $file_count -gt 0 ]]; then
local size_human
size_human=$(bytes_to_human "$total_bytes")
local size_kb=$(((total_bytes + 1023) / 1024))
if [[ "$DRY_RUN" == "true" ]]; then
echo -e " ${YELLOW}${ICON_DRY_RUN}${NC} $label${NC}, ${YELLOW}$file_count files, $size_human dry${NC}"
else
echo -e " ${GREEN}${ICON_SUCCESS}${NC} $label${NC}, ${GREEN}$file_count files, $size_human${NC}"
local line_color
line_color=$(cleanup_result_color_kb "$size_kb")
echo -e " ${line_color}${ICON_SUCCESS}${NC} $label${NC}, ${line_color}$file_count files, $size_human${NC}"
fi
local size_kb=$(((total_bytes + 1023) / 1024))
files_cleaned=$((files_cleaned + file_count))
total_size_cleaned=$((total_size_cleaned + size_kb))
total_items=$((total_items + 1))

View File

@@ -439,7 +439,9 @@ clean_xcode_device_support() {
done
if [[ $removed_count -gt 0 ]]; then
echo -e " ${GREEN}${ICON_SUCCESS}${NC} ${display_name} · removed ${removed_count} old versions, ${stale_size_human}"
local line_color
line_color=$(cleanup_result_color_kb "$stale_size_kb")
echo -e " ${line_color}${ICON_SUCCESS}${NC} ${display_name} · removed ${removed_count} old versions, ${line_color}${stale_size_human}${NC}"
note_activity
fi
fi
@@ -655,10 +657,12 @@ clean_xcode_simulator_runtime_volumes() {
if [[ $removed_count -gt 0 ]]; then
local removed_human
removed_human=$(bytes_to_human "$((removed_size_kb * 1024))")
local line_color
line_color=$(cleanup_result_color_kb "$removed_size_kb")
if [[ $skipped_protected -gt 0 ]]; then
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Xcode runtime volumes · removed ${removed_count} (${removed_human}), skipped ${skipped_protected} protected"
echo -e " ${line_color}${ICON_SUCCESS}${NC} Xcode runtime volumes · removed ${removed_count} (${line_color}${removed_human}${NC}), skipped ${skipped_protected} protected"
else
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Xcode runtime volumes · removed ${removed_count} (${removed_human})"
echo -e " ${line_color}${ICON_SUCCESS}${NC} Xcode runtime volumes · removed ${removed_count} (${line_color}${removed_human}${NC})"
fi
note_activity
else
@@ -745,9 +749,13 @@ clean_dev_mobile() {
fi
if ((removed_unavailable > 0)); then
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Xcode unavailable simulators · removed ${removed_unavailable}, ${unavailable_size_human}"
local line_color
line_color=$(cleanup_result_color_kb "$unavailable_size_kb")
echo -e " ${line_color}${ICON_SUCCESS}${NC} Xcode unavailable simulators · removed ${removed_unavailable}, ${line_color}${unavailable_size_human}${NC}"
else
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Xcode unavailable simulators · cleanup completed, ${unavailable_size_human}"
local line_color
line_color=$(cleanup_result_color_kb "$unavailable_size_kb")
echo -e " ${line_color}${ICON_SUCCESS}${NC} Xcode unavailable simulators · cleanup completed, ${line_color}${unavailable_size_human}${NC}"
fi
else
stop_section_spinner
@@ -793,7 +801,9 @@ clean_dev_mobile() {
if ((manually_removed > 0)); then
if ((manual_failed == 0)); then
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Xcode unavailable simulators · removed ${manually_removed} (fallback), ${unavailable_size_human}"
local line_color
line_color=$(cleanup_result_color_kb "$unavailable_size_kb")
echo -e " ${line_color}${ICON_SUCCESS}${NC} Xcode unavailable simulators · removed ${manually_removed} (fallback), ${line_color}${unavailable_size_human}${NC}"
else
echo -e " ${YELLOW}${ICON_WARNING}${NC} Xcode unavailable simulators · partially cleaned ${manually_removed}/${#unavailable_udids[@]}, ${unavailable_size_human}"
fi

View File

@@ -309,7 +309,9 @@ clean_time_machine_failed_backups() {
continue
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}"
local line_color
line_color=$(cleanup_result_color_kb "$size_kb")
echo -e " ${line_color}${ICON_SUCCESS}${NC} Incomplete backup: $backup_name${NC}, ${line_color}$size_human${NC}"
tm_cleaned=$((tm_cleaned + 1))
files_cleaned=$((files_cleaned + 1))
total_size_cleaned=$((total_size_cleaned + size_kb))
@@ -360,7 +362,9 @@ clean_time_machine_failed_backups() {
continue
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}"
local line_color
line_color=$(cleanup_result_color_kb "$size_kb")
echo -e " ${line_color}${ICON_SUCCESS}${NC} Incomplete APFS backup in $bundle_name: $backup_name${NC}, ${line_color}$size_human${NC}"
tm_cleaned=$((tm_cleaned + 1))
files_cleaned=$((files_cleaned + 1))
total_size_cleaned=$((total_size_cleaned + size_kb))

View File

@@ -233,7 +233,9 @@ clean_chrome_old_versions() {
if [[ "$DRY_RUN" == "true" ]]; then
echo -e " ${YELLOW}${ICON_DRY_RUN}${NC} Chrome old versions${NC}, ${YELLOW}${cleaned_count} dirs, $size_human dry${NC}"
else
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Chrome old versions${NC}, ${GREEN}${cleaned_count} dirs, $size_human${NC}"
local line_color
line_color=$(cleanup_result_color_kb "$total_size")
echo -e " ${line_color}${ICON_SUCCESS}${NC} Chrome old versions${NC}, ${line_color}${cleaned_count} dirs, $size_human${NC}"
fi
files_cleaned=$((files_cleaned + cleaned_count))
total_size_cleaned=$((total_size_cleaned + total_size))
@@ -319,7 +321,9 @@ clean_edge_old_versions() {
if [[ "$DRY_RUN" == "true" ]]; then
echo -e " ${YELLOW}${ICON_DRY_RUN}${NC} Edge old versions${NC}, ${YELLOW}${cleaned_count} dirs, $size_human dry${NC}"
else
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Edge old versions${NC}, ${GREEN}${cleaned_count} dirs, $size_human${NC}"
local line_color
line_color=$(cleanup_result_color_kb "$total_size")
echo -e " ${line_color}${ICON_SUCCESS}${NC} Edge old versions${NC}, ${line_color}${cleaned_count} dirs, $size_human${NC}"
fi
files_cleaned=$((files_cleaned + cleaned_count))
total_size_cleaned=$((total_size_cleaned + total_size))
@@ -381,7 +385,9 @@ clean_edge_updater_old_versions() {
if [[ "$DRY_RUN" == "true" ]]; then
echo -e " ${YELLOW}${ICON_DRY_RUN}${NC} Edge updater old versions${NC}, ${YELLOW}${cleaned_count} dirs, $size_human dry${NC}"
else
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Edge updater old versions${NC}, ${GREEN}${cleaned_count} dirs, $size_human${NC}"
local line_color
line_color=$(cleanup_result_color_kb "$total_size")
echo -e " ${line_color}${ICON_SUCCESS}${NC} Edge updater old versions${NC}, ${line_color}${cleaned_count} dirs, $size_human${NC}"
fi
files_cleaned=$((files_cleaned + cleaned_count))
total_size_cleaned=$((total_size_cleaned + total_size))
@@ -597,7 +603,9 @@ clean_app_caches() {
else
local size_human
size_human=$(bytes_to_human "$((total_size * 1024))")
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Sandboxed app caches${NC}, ${GREEN}$size_human${NC}"
local line_color
line_color=$(cleanup_result_color_kb "$total_size")
echo -e " ${line_color}${ICON_SUCCESS}${NC} Sandboxed app caches${NC}, ${line_color}$size_human${NC}"
fi
fi
files_cleaned=$((files_cleaned + cleaned_count))
@@ -793,7 +801,9 @@ clean_group_container_caches() {
else
local size_human
size_human=$(bytes_to_human "$((total_size * 1024))")
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Group Containers logs/caches${NC}, ${GREEN}$size_human${NC}"
local line_color
line_color=$(cleanup_result_color_kb "$total_size")
echo -e " ${line_color}${ICON_SUCCESS}${NC} Group Containers logs/caches${NC}, ${line_color}$size_human${NC}"
fi
fi
files_cleaned=$((files_cleaned + cleaned_count))
@@ -960,7 +970,9 @@ clean_external_volume_target() {
if [[ "$DRY_RUN" == "true" ]]; then
echo -e " ${YELLOW}${ICON_DRY_RUN}${NC} External volume cleanup${NC}, ${YELLOW}${volume_name}, $size_human dry${NC}"
else
echo -e " ${GREEN}${ICON_SUCCESS}${NC} External volume cleanup${NC}, ${GREEN}${volume_name}, $size_human${NC}"
local line_color
line_color=$(cleanup_result_color_kb "$total_size")
echo -e " ${line_color}${ICON_SUCCESS}${NC} External volume cleanup${NC}, ${line_color}${volume_name}, $size_human${NC}"
fi
files_cleaned=$((files_cleaned + cleaned_count))
total_size_cleaned=$((total_size_cleaned + total_size))
@@ -1340,10 +1352,12 @@ clean_application_support_logs() {
echo -e " ${YELLOW}${ICON_DRY_RUN}${NC} Application Support logs/caches${NC}, ${YELLOW}$size_human dry${NC}"
fi
else
local line_color
line_color=$(cleanup_result_color_kb "$total_size_kb")
if [[ "$total_size_partial" == "true" ]]; then
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Application Support logs/caches${NC}, ${GREEN}at least $size_human${NC}"
echo -e " ${line_color}${ICON_SUCCESS}${NC} Application Support logs/caches${NC}, ${line_color}at least $size_human${NC}"
else
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Application Support logs/caches${NC}, ${GREEN}$size_human${NC}"
echo -e " ${line_color}${ICON_SUCCESS}${NC} Application Support logs/caches${NC}, ${line_color}$size_human${NC}"
fi
fi
files_cleaned=$((files_cleaned + cleaned_count))