mirror of
https://github.com/tw93/Mole.git
synced 2026-02-08 23:09:20 +00:00
Improve performance and process handling
This commit is contained in:
@@ -241,7 +241,25 @@ clean_project_caches() {
|
|||||||
# 4. Clean up any stuck processes
|
# 4. Clean up any stuck processes
|
||||||
for pid in $next_pid $py_pid; do
|
for pid in $next_pid $py_pid; do
|
||||||
if kill -0 "$pid" 2> /dev/null; then
|
if kill -0 "$pid" 2> /dev/null; then
|
||||||
|
# Send TERM signal first
|
||||||
kill -TERM "$pid" 2> /dev/null || true
|
kill -TERM "$pid" 2> /dev/null || true
|
||||||
|
|
||||||
|
# Wait up to 2 seconds for graceful termination
|
||||||
|
local grace_period=0
|
||||||
|
while [[ $grace_period -lt 20 ]]; do
|
||||||
|
if ! kill -0 "$pid" 2> /dev/null; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
sleep 0.1
|
||||||
|
((grace_period++))
|
||||||
|
done
|
||||||
|
|
||||||
|
# Force kill if still running
|
||||||
|
if kill -0 "$pid" 2> /dev/null; then
|
||||||
|
kill -KILL "$pid" 2> /dev/null || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Final wait (should be instant now)
|
||||||
wait "$pid" 2> /dev/null || true
|
wait "$pid" 2> /dev/null || true
|
||||||
else
|
else
|
||||||
wait "$pid" 2> /dev/null || true
|
wait "$pid" 2> /dev/null || true
|
||||||
|
|||||||
@@ -321,12 +321,25 @@ clean_dev_network() {
|
|||||||
safe_clean ~/Library/Caches/wget/* "macOS wget cache"
|
safe_clean ~/Library/Caches/wget/* "macOS wget cache"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Clean orphaned SQLite temporary files (-shm and -wal files)
|
||||||
|
# Strategy: Only clean truly orphaned temp files where base database is missing
|
||||||
|
# This is fast and safe - skip complex checks for files with existing base DB
|
||||||
|
# Env: DRY_RUN
|
||||||
|
clean_sqlite_temp_files() {
|
||||||
|
# Skip this cleanup due to low ROI (收益比低,经常没东西可清理)
|
||||||
|
# Find scan is still slow even optimized, and orphaned files are rare
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
# Main developer tools cleanup function
|
# Main developer tools cleanup function
|
||||||
# Calls all specialized cleanup functions
|
# Calls all specialized cleanup functions
|
||||||
# Env: DRY_RUN
|
# Env: DRY_RUN
|
||||||
clean_developer_tools() {
|
clean_developer_tools() {
|
||||||
stop_section_spinner
|
stop_section_spinner
|
||||||
|
|
||||||
|
# Clean SQLite temporary files first
|
||||||
|
clean_sqlite_temp_files
|
||||||
|
|
||||||
clean_dev_npm
|
clean_dev_npm
|
||||||
clean_dev_python
|
clean_dev_python
|
||||||
clean_dev_go
|
clean_dev_go
|
||||||
|
|||||||
@@ -78,8 +78,9 @@ scan_external_volumes() {
|
|||||||
start_section_spinner "Scanning $volume_count external volume(s)..."
|
start_section_spinner "Scanning $volume_count external volume(s)..."
|
||||||
|
|
||||||
for volume in "${candidate_volumes[@]}"; do
|
for volume in "${candidate_volumes[@]}"; do
|
||||||
# Verify volume is actually mounted (reduced timeout from 2s to 1s)
|
# Re-verify volume is still accessible (may have been unmounted since initial scan)
|
||||||
run_with_timeout 1 mount | grep -q "on $volume " || continue
|
# Use simple directory check instead of slow mount command for better performance
|
||||||
|
[[ -d "$volume" && -r "$volume" ]] || continue
|
||||||
|
|
||||||
# 1. Clean Trash on volume
|
# 1. Clean Trash on volume
|
||||||
local volume_trash="$volume/.Trashes"
|
local volume_trash="$volume/.Trashes"
|
||||||
|
|||||||
@@ -185,13 +185,13 @@ safe_sudo_find_delete() {
|
|||||||
local age_days="${3:-7}"
|
local age_days="${3:-7}"
|
||||||
local type_filter="${4:-f}"
|
local type_filter="${4:-f}"
|
||||||
|
|
||||||
# Validate base directory
|
# Validate base directory (use sudo for permission-restricted dirs)
|
||||||
if [[ ! -d "$base_dir" ]]; then
|
if ! sudo test -d "$base_dir" 2>/dev/null; then
|
||||||
log_error "Directory does not exist: $base_dir"
|
debug_log "Directory does not exist (skipping): $base_dir"
|
||||||
return 1
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -L "$base_dir" ]]; then
|
if sudo test -L "$base_dir" 2>/dev/null; then
|
||||||
log_error "Refusing to search symlinked directory: $base_dir"
|
log_error "Refusing to search symlinked directory: $base_dir"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user