From a29cadbfd0f8046358a194d62f3e9f517136dbbb Mon Sep 17 00:00:00 2001 From: tw93 Date: Mon, 16 Feb 2026 15:54:16 +0800 Subject: [PATCH] fix(purge): resolve trap conflict between purge.sh and project.sh - Add guard flag in cleanup_monitor to prevent duplicate execution - Check for existing trap in project.sh before setting new one - Prevents crash when user presses Ctrl-C or scan process fails --- bin/purge.sh | 7 ++++++- lib/clean/project.sh | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/bin/purge.sh b/bin/purge.sh index ce67c57..58e9f0f 100755 --- a/bin/purge.sh +++ b/bin/purge.sh @@ -68,8 +68,13 @@ perform_purge() { local stats_dir="${XDG_CACHE_HOME:-$HOME/.cache}/mole" local monitor_pid="" - # Cleanup function + # Cleanup function - use flag to prevent duplicate execution + _cleanup_done=false cleanup_monitor() { + # Prevent multiple cleanup executions from trap conflicts + [[ "$_cleanup_done" == "true" ]] && return + _cleanup_done=true + # Remove scanning file to stop monitor rm -f "$stats_dir/purge_scanning" 2> /dev/null || true diff --git a/lib/clean/project.sh b/lib/clean/project.sh index 762be9d..eecf872 100644 --- a/lib/clean/project.sh +++ b/lib/clean/project.sh @@ -786,7 +786,12 @@ clean_project_artifacts() { echo "" exit 130 } - trap cleanup_scan INT TERM + # Set up signal handling only if not already set by parent script + # This prevents trap conflicts between purge.sh and project.sh + if [[ -z "${_MO_PURGE_TRAP_SET:-}" ]]; then + trap cleanup_scan INT TERM + export _MO_PURGE_TRAP_SET=1 + fi # Scanning is started from purge.sh with start_inline_spinner # Launch all scans in parallel for path in "${PURGE_SEARCH_PATHS[@]}"; do