mirror of
https://github.com/tw93/Mole.git
synced 2026-02-05 21:58:01 +00:00
Merge branch 'dev'
This commit is contained in:
34
bin/clean.sh
34
bin/clean.sh
@@ -251,13 +251,15 @@ safe_clean() {
|
||||
|
||||
# Show progress indicator for potentially slow operations
|
||||
if [[ ${#existing_paths[@]} -gt 3 ]]; then
|
||||
if [[ -t 1 ]]; then MOLE_SPINNER_PREFIX=" " start_inline_spinner "Checking items with whitelist safety..."; fi
|
||||
local total_paths=${#existing_paths[@]}
|
||||
if [[ -t 1 ]]; then MOLE_SPINNER_PREFIX=" " start_inline_spinner "Scanning $total_paths items..."; fi
|
||||
local temp_dir
|
||||
temp_dir=$(create_temp_dir)
|
||||
|
||||
# Parallel processing (bash 3.2 compatible)
|
||||
local -a pids=()
|
||||
local idx=0
|
||||
local completed=0
|
||||
for path in "${existing_paths[@]}"; do
|
||||
(
|
||||
local size
|
||||
@@ -275,11 +277,18 @@ safe_clean() {
|
||||
if ((${#pids[@]} >= MAX_PARALLEL_JOBS)); then
|
||||
wait "${pids[0]}" 2> /dev/null || true
|
||||
pids=("${pids[@]:1}")
|
||||
((completed++))
|
||||
# Update progress every 10 items for smoother display
|
||||
if [[ -t 1 ]] && ((completed % 10 == 0)); then
|
||||
stop_inline_spinner
|
||||
MOLE_SPINNER_PREFIX=" " start_inline_spinner "Scanning items ($completed/$total_paths)..."
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
for pid in "${pids[@]}"; do
|
||||
wait "$pid" 2> /dev/null || true
|
||||
((completed++))
|
||||
done
|
||||
|
||||
# Read results using same index
|
||||
@@ -303,7 +312,8 @@ safe_clean() {
|
||||
# Temp dir will be auto-cleaned by cleanup_temp_files
|
||||
else
|
||||
# Show progress for small batches too (simpler jobs)
|
||||
if [[ -t 1 ]]; then MOLE_SPINNER_PREFIX=" " start_inline_spinner "Checking items with whitelist safety..."; fi
|
||||
local total_paths=${#existing_paths[@]}
|
||||
if [[ -t 1 ]]; then MOLE_SPINNER_PREFIX=" " start_inline_spinner "Scanning $total_paths items..."; fi
|
||||
|
||||
for path in "${existing_paths[@]}"; do
|
||||
local size_bytes
|
||||
@@ -658,7 +668,25 @@ perform_cleanup() {
|
||||
safe_clean /usr/local/var/homebrew/locks/* "Homebrew lock files (Intel)"
|
||||
if command -v brew > /dev/null 2>&1; then
|
||||
if [[ "$DRY_RUN" != "true" ]]; then
|
||||
MOLE_CMD_TIMEOUT=300 clean_tool_cache "Homebrew cleanup" brew cleanup -s --prune=all
|
||||
if [[ -t 1 ]]; then MOLE_SPINNER_PREFIX=" " start_inline_spinner "Homebrew cleanup..."; fi
|
||||
# Run brew cleanup and capture output
|
||||
local brew_output
|
||||
brew_output=$(brew cleanup -s --prune=all 2>&1)
|
||||
if [[ -t 1 ]]; then stop_inline_spinner; fi
|
||||
|
||||
# Show summary of what was cleaned
|
||||
local removed_count=$(echo "$brew_output" | grep -c "Removing:" || echo "0")
|
||||
local freed_space=$(echo "$brew_output" | grep -o "[0-9.]*[KMGT]B freed" | tail -1 || echo "")
|
||||
|
||||
if [[ $removed_count -gt 0 ]] || [[ -n "$freed_space" ]]; then
|
||||
if [[ -n "$freed_space" ]]; then
|
||||
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Homebrew cleanup ${GREEN}($freed_space)${NC}"
|
||||
else
|
||||
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Homebrew cleanup (${removed_count} items)"
|
||||
fi
|
||||
else
|
||||
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Homebrew cleanup"
|
||||
fi
|
||||
else
|
||||
echo -e " ${YELLOW}→${NC} Homebrew (would cleanup)"
|
||||
fi
|
||||
|
||||
@@ -104,10 +104,18 @@ scan_applications() {
|
||||
local cache_dir="$HOME/.cache/mole"
|
||||
local cache_file="$cache_dir/app_scan_cache"
|
||||
local cache_meta="$cache_dir/app_scan_meta"
|
||||
local cache_dir_mtime="$cache_dir/app_dir_mtime"
|
||||
local cache_ttl=86400 # 24 hours cache validity (app count change will trigger refresh)
|
||||
|
||||
mkdir -p "$cache_dir" 2> /dev/null
|
||||
|
||||
# Get modification time of app directories to detect new installations
|
||||
local sys_app_mtime
|
||||
sys_app_mtime=$(stat -f%m "/Applications" 2> /dev/null || echo "0")
|
||||
local user_app_mtime
|
||||
user_app_mtime=$(stat -f%m "$HOME/Applications" 2> /dev/null || echo "0")
|
||||
local combined_mtime=$((sys_app_mtime + user_app_mtime))
|
||||
|
||||
# Quick count of current apps (system + user directories)
|
||||
local current_app_count
|
||||
current_app_count=$(
|
||||
@@ -118,13 +126,15 @@ scan_applications() {
|
||||
)
|
||||
|
||||
# Check if cache is valid unless explicitly disabled
|
||||
if [[ -f "$cache_file" && -f "$cache_meta" ]]; then
|
||||
if [[ -f "$cache_file" && -f "$cache_meta" && -f "$cache_dir_mtime" ]]; then
|
||||
local cache_age=$(($(date +%s) - $(stat -f%m "$cache_file" 2> /dev/null || echo 0)))
|
||||
local cached_app_count
|
||||
cached_app_count=$(cat "$cache_meta" 2> /dev/null || echo "0")
|
||||
local cached_dir_mtime
|
||||
cached_dir_mtime=$(cat "$cache_dir_mtime" 2> /dev/null || echo "0")
|
||||
|
||||
# Cache is valid if: age < TTL AND app count matches
|
||||
if [[ $cache_age -lt $cache_ttl && "$cached_app_count" == "$current_app_count" ]]; then
|
||||
# Cache is valid if: age < TTL AND app count matches AND directory not modified
|
||||
if [[ $cache_age -lt $cache_ttl && "$cached_app_count" == "$current_app_count" && "$cached_dir_mtime" == "$combined_mtime" ]]; then
|
||||
# Silent - cache hit, return immediately without any output
|
||||
echo "$cache_file"
|
||||
return 0
|
||||
@@ -371,9 +381,10 @@ scan_applications() {
|
||||
}
|
||||
rm -f "$temp_file"
|
||||
|
||||
# Update cache with app count metadata
|
||||
# Update cache with app count metadata and directory modification time
|
||||
cp "${temp_file}.sorted" "$cache_file" 2> /dev/null || true
|
||||
echo "$current_app_count" > "$cache_meta" 2> /dev/null || true
|
||||
echo "$combined_mtime" > "$cache_dir_mtime" 2> /dev/null || true
|
||||
|
||||
# Verify sorted file exists before returning
|
||||
if [[ -f "${temp_file}.sorted" ]]; then
|
||||
|
||||
Reference in New Issue
Block a user