mirror of
https://github.com/tw93/Mole.git
synced 2026-03-22 20:15:07 +00:00
perf: improve Application Support scan progress and size accounting
This commit is contained in:
@@ -720,7 +720,7 @@ clean_application_support_logs() {
|
|||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
start_section_spinner "Scanning Application Support..."
|
start_section_spinner "Scanning Application Support..."
|
||||||
local total_size=0
|
local total_size_bytes=0
|
||||||
local cleaned_count=0
|
local cleaned_count=0
|
||||||
local found_any=false
|
local found_any=false
|
||||||
# Enable nullglob for safe globbing.
|
# Enable nullglob for safe globbing.
|
||||||
@@ -729,7 +729,8 @@ clean_application_support_logs() {
|
|||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
local app_count=0
|
local app_count=0
|
||||||
local total_apps
|
local total_apps
|
||||||
total_apps=$(find ~/Library/Application\ Support -mindepth 1 -maxdepth 1 -type d 2> /dev/null | wc -l | tr -d ' ')
|
total_apps=$(command find "$HOME/Library/Application Support" -mindepth 1 -maxdepth 1 -type d 2> /dev/null | wc -l | tr -d ' ')
|
||||||
|
[[ "$total_apps" =~ ^[0-9]+$ ]] || total_apps=0
|
||||||
local last_progress_update
|
local last_progress_update
|
||||||
last_progress_update=$(get_epoch_seconds)
|
last_progress_update=$(get_epoch_seconds)
|
||||||
for app_dir in ~/Library/Application\ Support/*; do
|
for app_dir in ~/Library/Application\ Support/*; do
|
||||||
@@ -756,21 +757,32 @@ clean_application_support_logs() {
|
|||||||
for candidate in "${start_candidates[@]}"; do
|
for candidate in "${start_candidates[@]}"; do
|
||||||
if [[ -d "$candidate" ]]; then
|
if [[ -d "$candidate" ]]; then
|
||||||
local item_found=false
|
local item_found=false
|
||||||
local candidate_size=0
|
local candidate_size_bytes=0
|
||||||
|
local candidate_item_count=0
|
||||||
while IFS= read -r -d '' item; do
|
while IFS= read -r -d '' item; do
|
||||||
[[ -e "$item" ]] || continue
|
[[ -e "$item" ]] || continue
|
||||||
item_found=true
|
item_found=true
|
||||||
|
((candidate_item_count++))
|
||||||
if [[ -f "$item" && ! -L "$item" ]]; then
|
if [[ -f "$item" && ! -L "$item" ]]; then
|
||||||
local bytes
|
local bytes
|
||||||
bytes=$(stat -f%z "$item" 2> /dev/null || echo "0")
|
bytes=$(stat -f%z "$item" 2> /dev/null || echo "0")
|
||||||
[[ "$bytes" =~ ^[0-9]+$ ]] && ((candidate_size += bytes / 1024)) || true
|
[[ "$bytes" =~ ^[0-9]+$ ]] && ((candidate_size_bytes += bytes)) || true
|
||||||
|
fi
|
||||||
|
if ((candidate_item_count % 250 == 0)); then
|
||||||
|
local current_time
|
||||||
|
current_time=$(get_epoch_seconds)
|
||||||
|
if [[ "$current_time" =~ ^[0-9]+$ ]] && ((current_time - last_progress_update >= 1)); then
|
||||||
|
stop_section_spinner
|
||||||
|
start_section_spinner "Scanning Application Support... $app_count/$total_apps ($app_name: $candidate_item_count items)"
|
||||||
|
last_progress_update=$current_time
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
if [[ "$DRY_RUN" != "true" ]]; then
|
if [[ "$DRY_RUN" != "true" ]]; then
|
||||||
safe_remove "$item" true > /dev/null 2>&1 || true
|
safe_remove "$item" true > /dev/null 2>&1 || true
|
||||||
fi
|
fi
|
||||||
done < <(command find "$candidate" -mindepth 1 -maxdepth 1 -print0 2> /dev/null || true)
|
done < <(command find "$candidate" -mindepth 1 -maxdepth 1 -print0 2> /dev/null || true)
|
||||||
if [[ "$item_found" == "true" ]]; then
|
if [[ "$item_found" == "true" ]]; then
|
||||||
((total_size += candidate_size))
|
((total_size_bytes += candidate_size_bytes))
|
||||||
((cleaned_count++))
|
((cleaned_count++))
|
||||||
found_any=true
|
found_any=true
|
||||||
fi
|
fi
|
||||||
@@ -787,21 +799,32 @@ clean_application_support_logs() {
|
|||||||
for candidate in "${gc_candidates[@]}"; do
|
for candidate in "${gc_candidates[@]}"; do
|
||||||
if [[ -d "$candidate" ]]; then
|
if [[ -d "$candidate" ]]; then
|
||||||
local item_found=false
|
local item_found=false
|
||||||
local candidate_size=0
|
local candidate_size_bytes=0
|
||||||
|
local candidate_item_count=0
|
||||||
while IFS= read -r -d '' item; do
|
while IFS= read -r -d '' item; do
|
||||||
[[ -e "$item" ]] || continue
|
[[ -e "$item" ]] || continue
|
||||||
item_found=true
|
item_found=true
|
||||||
|
((candidate_item_count++))
|
||||||
if [[ -f "$item" && ! -L "$item" ]]; then
|
if [[ -f "$item" && ! -L "$item" ]]; then
|
||||||
local bytes
|
local bytes
|
||||||
bytes=$(stat -f%z "$item" 2> /dev/null || echo "0")
|
bytes=$(stat -f%z "$item" 2> /dev/null || echo "0")
|
||||||
[[ "$bytes" =~ ^[0-9]+$ ]] && ((candidate_size += bytes / 1024)) || true
|
[[ "$bytes" =~ ^[0-9]+$ ]] && ((candidate_size_bytes += bytes)) || true
|
||||||
|
fi
|
||||||
|
if ((candidate_item_count % 250 == 0)); then
|
||||||
|
local current_time
|
||||||
|
current_time=$(get_epoch_seconds)
|
||||||
|
if [[ "$current_time" =~ ^[0-9]+$ ]] && ((current_time - last_progress_update >= 1)); then
|
||||||
|
stop_section_spinner
|
||||||
|
start_section_spinner "Scanning Application Support... group container ($container: $candidate_item_count items)"
|
||||||
|
last_progress_update=$current_time
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
if [[ "$DRY_RUN" != "true" ]]; then
|
if [[ "$DRY_RUN" != "true" ]]; then
|
||||||
safe_remove "$item" true > /dev/null 2>&1 || true
|
safe_remove "$item" true > /dev/null 2>&1 || true
|
||||||
fi
|
fi
|
||||||
done < <(command find "$candidate" -mindepth 1 -maxdepth 1 -print0 2> /dev/null || true)
|
done < <(command find "$candidate" -mindepth 1 -maxdepth 1 -print0 2> /dev/null || true)
|
||||||
if [[ "$item_found" == "true" ]]; then
|
if [[ "$item_found" == "true" ]]; then
|
||||||
((total_size += candidate_size))
|
((total_size_bytes += candidate_size_bytes))
|
||||||
((cleaned_count++))
|
((cleaned_count++))
|
||||||
found_any=true
|
found_any=true
|
||||||
fi
|
fi
|
||||||
@@ -812,14 +835,15 @@ clean_application_support_logs() {
|
|||||||
stop_section_spinner
|
stop_section_spinner
|
||||||
if [[ "$found_any" == "true" ]]; then
|
if [[ "$found_any" == "true" ]]; then
|
||||||
local size_human
|
local size_human
|
||||||
size_human=$(bytes_to_human "$((total_size * 1024))")
|
size_human=$(bytes_to_human "$total_size_bytes")
|
||||||
|
local total_size_kb=$(((total_size_bytes + 1023) / 1024))
|
||||||
if [[ "$DRY_RUN" == "true" ]]; then
|
if [[ "$DRY_RUN" == "true" ]]; then
|
||||||
echo -e " ${YELLOW}${ICON_DRY_RUN}${NC} Application Support logs/caches${NC}, ${YELLOW}$size_human dry${NC}"
|
echo -e " ${YELLOW}${ICON_DRY_RUN}${NC} Application Support logs/caches${NC}, ${YELLOW}$size_human dry${NC}"
|
||||||
else
|
else
|
||||||
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Application Support logs/caches${NC}, ${GREEN}$size_human${NC}"
|
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Application Support logs/caches${NC}, ${GREEN}$size_human${NC}"
|
||||||
fi
|
fi
|
||||||
((files_cleaned += cleaned_count))
|
((files_cleaned += cleaned_count))
|
||||||
((total_size_cleaned += total_size))
|
((total_size_cleaned += total_size_kb))
|
||||||
((total_items++))
|
((total_items++))
|
||||||
note_activity
|
note_activity
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user