Skip to content

Commit 0f3ef38

Browse files
authored
perf(copy): limit find depth for simple directory patterns (#130)
1 parent 161b478 commit 0f3ef38

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/copy.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,15 @@ copy_directories() {
331331
# Find directories matching the pattern
332332
# Use -path for patterns with slashes (e.g., vendor/bundle), -name for basenames
333333
# Note: case inside $() inside heredocs breaks Bash 3.2, so compute first
334+
# Use -maxdepth 1 for simple basenames to avoid scanning entire repo (e.g., node_modules)
335+
# Falls back to recursive search if shallow search finds nothing
334336
local find_results
335337
case "$pattern" in
336-
*/*) find_results=$(find . -type d -path "./$pattern" 2>/dev/null) ;;
337-
*) find_results=$(find . -type d -name "$pattern" 2>/dev/null) ;;
338+
*/*) find_results=$(find . -type d -path "./$pattern" 2>/dev/null || true) ;;
339+
*) find_results=$(find . -maxdepth 1 -type d -name "$pattern" 2>/dev/null || true)
340+
if [ -z "$find_results" ]; then
341+
find_results=$(find . -type d -name "$pattern" 2>/dev/null || true)
342+
fi ;;
338343
esac
339344

340345
while IFS= read -r dir_path; do

0 commit comments

Comments
 (0)