1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-04 17:24:45 +00:00

fix: improve performance of cache cleanup using find -delete

This commit is contained in:
tw93
2026-01-31 20:19:38 +08:00
parent 8ac71a3937
commit 7d62fa5e65

View File

@@ -457,15 +457,18 @@ process_container_cache() {
found_any=true found_any=true
((cleaned_count++)) ((cleaned_count++))
if [[ "$DRY_RUN" != "true" ]]; then if [[ "$DRY_RUN" != "true" ]]; then
# Clean contents safely with local nullglob. # For directories with many files, use find -delete for performance
local _ng_state if ! find "$cache_dir" -mindepth 1 -delete 2> /dev/null; then
_ng_state=$(shopt -p nullglob || true) # Fallback: try item-by-item if find fails
shopt -s nullglob local _ng_state
for item in "$cache_dir"/*; do _ng_state=$(shopt -p nullglob || true)
[[ -e "$item" ]] || continue shopt -s nullglob
safe_remove "$item" true || true for item in "$cache_dir"/*; do
done [[ -e "$item" ]] || continue
eval "$_ng_state" safe_remove "$item" true || true
done
eval "$_ng_state"
fi
fi fi
fi fi
} }
@@ -604,10 +607,15 @@ clean_application_support_logs() {
((cleaned_count++)) ((cleaned_count++))
found_any=true found_any=true
if [[ "$DRY_RUN" != "true" ]]; then if [[ "$DRY_RUN" != "true" ]]; then
for item in "$candidate"/*; do # For directories with many files, use find -delete for performance
[[ -e "$item" ]] || continue # This avoids shell expansion and individual safe_remove calls
safe_remove "$item" true > /dev/null 2>&1 || true if ! find "$candidate" -mindepth 1 -delete 2> /dev/null; then
done # Fallback: try item-by-item if find fails
for item in "$candidate"/*; do
[[ -e "$item" ]] || continue
safe_remove "$item" true > /dev/null 2>&1 || true
done
fi
fi fi
fi fi
fi fi