From 7f787b5c04eaea0011c361ec4551b3d8c91b7af9 Mon Sep 17 00:00:00 2001 From: tw93 Date: Wed, 4 Feb 2026 20:05:09 +0800 Subject: [PATCH] fix: implement MO_USE_FIND and improve fd fallback logic Fixes the issue reported in PR #410 where mo purge fails to find artifacts when fd returns empty results. Changes: - Implement MO_USE_FIND environment variable to force using find - Improve fd fallback: check if fd output is empty (-s test) - Add debug logging to show which tool is being used - If fd returns no results, fallback to find automatically This fixes the root cause where fd successfully runs (exit 0) but finds nothing, preventing the find fallback from being triggered. --- lib/clean/project.sh | 10 +++++----- scripts/setup-quick-launchers.sh | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/clean/project.sh b/lib/clean/project.sh index 628522a..4c6606d 100644 --- a/lib/clean/project.sh +++ b/lib/clean/project.sh @@ -379,7 +379,7 @@ scan_purge_targets() { # Allow forcing find via MO_USE_FIND environment variable if [[ "${MO_USE_FIND:-0}" == "1" ]]; then - debug "MO_USE_FIND=1: Forcing find instead of fd" + debug_log "MO_USE_FIND=1: Forcing find instead of fd" use_find=true elif command -v fd > /dev/null 2>&1; then # Escape regex special characters in target names for fd patterns @@ -410,20 +410,20 @@ scan_purge_targets() { if fd "${fd_args[@]}" "$pattern" "$search_path" 2> /dev/null > "$output_file.raw"; then # Check if fd actually found anything - if empty, fallback to find if [[ -s "$output_file.raw" ]]; then - debug "Using fd for scanning (found results)" + debug_log "Using fd for scanning (found results)" use_find=false process_scan_results "$output_file.raw" else - debug "fd returned empty results, falling back to find" + debug_log "fd returned empty results, falling back to find" rm -f "$output_file.raw" fi else - debug "fd command failed, falling back to find" + debug_log "fd command failed, falling back to find" fi fi if [[ "$use_find" == "true" ]]; then - debug "Using find for scanning" + debug_log "Using find for scanning" # Pruned find avoids descending into heavy directories. local prune_dirs=(".git" "Library" ".Trash" "Applications") local purge_targets=("${PURGE_TARGETS[@]}") diff --git a/scripts/setup-quick-launchers.sh b/scripts/setup-quick-launchers.sh index e72080d..60f77af 100755 --- a/scripts/setup-quick-launchers.sh +++ b/scripts/setup-quick-launchers.sh @@ -69,7 +69,7 @@ echo "🐹 Running ${title}..." echo "" # Command to execute -_MO_RAW_CMD="${raw_cmd}" +_MO_RAW_CMD='${raw_cmd}' _MO_CMD_ESCAPED="${cmd_escaped}" has_app() {