1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-11 07:44:20 +00:00

Support debug

This commit is contained in:
Tw93
2025-12-05 17:16:46 +08:00
parent 5761fd87c8
commit b939442e92
11 changed files with 160 additions and 30 deletions

View File

@@ -177,6 +177,7 @@ start_section() {
TRACK_SECTION=1
SECTION_ACTIVITY=0
CURRENT_SECTION="$1"
debug_log "Starting section: $1"
echo ""
echo -e "${PURPLE_BOLD}${ICON_ARROW} $1${NC}"
@@ -212,6 +213,8 @@ safe_clean() {
targets=("${@:1:$#-1}")
fi
debug_log "safe_clean: description='$description', target_count=${#targets[@]}"
local removed_any=0
local total_size_bytes=0
local total_count=0
@@ -461,6 +464,9 @@ start_cleanup() {
echo -e "${PURPLE_BOLD}Clean Your Mac${NC}"
echo ""
debug_log "Starting cleanup process"
debug_log "DRY_RUN=$DRY_RUN, SYSTEM_CLEAN=$SYSTEM_CLEAN"
if [[ "$DRY_RUN" != "true" && -t 0 ]]; then
echo -e "${YELLOW}${NC} First time? Run ${GRAY}mo clean --dry-run${NC} first to preview changes"
fi
@@ -469,6 +475,7 @@ start_cleanup() {
echo -e "${YELLOW}Dry Run Mode${NC} - Preview only, no deletions"
echo ""
SYSTEM_CLEAN=false
debug_log "Dry run mode enabled"
# Initialize export list file
mkdir -p "$(dirname "$EXPORT_LIST_FILE")"
@@ -536,6 +543,13 @@ EOF
perform_cleanup() {
echo -e "${BLUE}${ICON_ADMIN}${NC} $(detect_architecture) | Free space: $(get_free_space)"
debug_log "Whitelist patterns loaded: ${#WHITELIST_PATTERNS[@]}"
if [[ "${MO_DEBUG:-}" == "1" && ${#WHITELIST_PATTERNS[@]} -gt 0 ]]; then
for pattern in "${WHITELIST_PATTERNS[@]}"; do
debug_log " Whitelist: $pattern"
done
fi
# Pre-check TCC permissions upfront (delegated to clean_caches module)
check_tcc_permissions

View File

@@ -385,8 +385,8 @@ main() {
log_error "Invalid system health data format"
echo -e "${YELLOW}Tip:${NC} Check if jq, awk, sysctl, and df commands are available"
if [[ "${MO_DEBUG:-}" == "1" ]]; then
echo "DEBUG: Generated JSON:"
echo "$health_json"
debug_log "Generated JSON:"
debug_log "$health_json"
fi
exit 1
fi
@@ -398,17 +398,13 @@ main() {
# Show system health
show_system_health "$health_json"
if [[ "${MO_DEBUG:-}" == "1" ]]; then
echo "DEBUG: System health displayed"
fi
debug_log "System health displayed"
# Parse and display optimizations
local -a safe_items=()
local -a confirm_items=()
if [[ "${MO_DEBUG:-}" == "1" ]]; then
echo "DEBUG: Parsing optimizations..."
fi
debug_log "Parsing optimizations..."
# Use temp file instead of process substitution to avoid hanging
local opts_file
@@ -417,7 +413,7 @@ main() {
if [[ "${MO_DEBUG:-}" == "1" ]]; then
local opt_count=$(wc -l < "$opts_file" | tr -d ' ')
echo "DEBUG: Found $opt_count optimizations"
debug_log "Found $opt_count optimizations"
fi
while IFS= read -r opt_json; do
@@ -438,23 +434,16 @@ main() {
fi
done < "$opts_file"
if [[ "${MO_DEBUG:-}" == "1" ]]; then
echo "DEBUG: Parsing complete. Safe: ${#safe_items[@]}, Confirm: ${#confirm_items[@]}"
fi
debug_log "Parsing complete. Safe: ${#safe_items[@]}, Confirm: ${#confirm_items[@]}"
# Execute all optimizations
local first_heading=true
# Debug: show what we're about to do
if [[ "${MO_DEBUG:-}" == "1" ]]; then
echo "DEBUG: About to request sudo. Safe items: ${#safe_items[@]}, Confirm items: ${#confirm_items[@]}"
fi
debug_log "About to request sudo. Safe items: ${#safe_items[@]}, Confirm items: ${#confirm_items[@]}"
ensure_sudo_session "System optimization requires admin access" || true
if [[ "${MO_DEBUG:-}" == "1" ]]; then
echo "DEBUG: Sudo session established or skipped"
fi
debug_log "Sudo session established or skipped"
# Run safe optimizations
if [[ ${#safe_items[@]} -gt 0 ]]; then

View File

@@ -69,6 +69,7 @@ format_last_used_summary() {
# Scan applications and collect information
scan_applications() {
debug_log "scan_applications: Starting application scan"
# Simplified cache: only check timestamp (24h TTL)
local cache_dir="$HOME/.cache/mole"
local cache_file="$cache_dir/app_scan_cache"
@@ -82,9 +83,13 @@ scan_applications() {
[[ $cache_age -eq $(date +%s) ]] && cache_age=86401 # Handle missing file
if [[ $cache_age -lt $cache_ttl ]]; then
# Cache hit - return immediately
debug_log "scan_applications: Using cached app list (age: ${cache_age}s)"
echo "$cache_file"
return 0
fi
debug_log "scan_applications: Cache expired (age: ${cache_age}s > ${cache_ttl}s)"
else
debug_log "scan_applications: No cache found, performing fresh scan"
fi
# Cache miss - show scanning feedback below