@@ -408,31 +408,34 @@ try_pgupgrade ()
408
408
run_pgupgrade
409
409
}
410
410
411
- # get_matched_files finds file for image extending
412
- function get_matched_files() {
413
- local custom_dir default_dir
414
- custom_dir=" $1 "
415
- default_dir=" $2 "
416
- files_matched=" $3 "
417
- find " $default_dir " -maxdepth 1 -type f -name " $files_matched " -printf " %f\n"
418
- [ -d " $custom_dir " ] && find " $custom_dir " -maxdepth 1 -type f -name " $files_matched " -printf " %f\n"
411
+ # get_matched_files PATTERN DIR [DIR ...]
412
+ # ---------------------------------------
413
+ # Print all basenames for files matching PATTERN in DIRs.
414
+ get_matched_files ()
415
+ {
416
+ local pattern=$1 dir
417
+ shift
418
+ for dir; do
419
+ test -d " $dir " || continue
420
+ find " $dir " -maxdepth 1 -type f -name " $pattern " -printf " %f\n"
421
+ done
419
422
}
420
423
421
- # process_extending_files process extending files in $1 and $2 directories
422
- # - source all *.sh files
423
- # (if there are files with same name source only file from $1)
424
- function process_extending_files() {
425
- local custom_dir default_dir
426
- custom_dir=$1
427
- default_dir=$2
428
-
424
+ # process_extending_files DIR [DIR ...]
425
+ # -------------------------------------
426
+ # Source all *.sh files in DIRs in alphabetical order, but if the file exists in
427
+ # more then one DIR, source only the first occurrence (first found wins).
428
+ process_extending_files ()
429
+ {
430
+ local filename dir
429
431
while read filename ; do
430
- echo " => sourcing $filename ..."
431
- # Custom file is prefered
432
- if [ -f $custom_dir /$filename ]; then
433
- source $custom_dir /$filename
434
- elif [ -f $default_dir /$filename ]; then
435
- source $default_dir /$filename
436
- fi
437
- done <<< " $(get_matched_files " $custom_dir " " $default_dir " '*.sh' | sort -u)"
432
+ for dir in " $@ " ; do
433
+ local file=" $dir /$filename "
434
+ if test -f " $file " ; then
435
+ echo " => sourcing $file ..."
436
+ source " $file "
437
+ break
438
+ fi
439
+ done
440
+ done <<< " $(get_matched_files '*.sh' " $@ " | sort -u)"
438
441
}
0 commit comments