1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-04 15:04:42 +00:00

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.
This commit is contained in:
tw93
2026-02-04 20:05:09 +08:00
parent d8b396533d
commit 7f787b5c04
2 changed files with 6 additions and 6 deletions

View File

@@ -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[@]}")