aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2012-10-17 23:17:15 +0200
committerLudovic Courtès <ludo@gnu.org>2012-10-17 23:25:25 +0200
commit4c261f4169b9da6b8a04d420422426e5548feac4 (patch)
tree29efe55ddaf529e8520c69248ca7496c549d0c97
parentc0746cc9dbf178e0358e93034072a60b6dfc24a1 (diff)
downloadguix-4c261f4169b9da6b8a04d420422426e5548feac4.tar
guix-4c261f4169b9da6b8a04d420422426e5548feac4.tar.gz
utils: Add `find-files'.
* guix/build/utils.scm (find-files): New procedure.
-rw-r--r--guix/build/utils.scm27
1 files changed, 27 insertions, 0 deletions
diff --git a/guix/build/utils.scm b/guix/build/utils.scm
index 741f5201bb..26bdfff1db 100644
--- a/guix/build/utils.scm
+++ b/guix/build/utils.scm
@@ -29,6 +29,8 @@
with-directory-excursion
mkdir-p
copy-recursively
+ find-files
+
set-path-environment-variable
search-path-as-string->list
list->search-path-as-string
@@ -117,6 +119,31 @@
#t
source))
+(define (find-files dir regexp)
+ "Return the list of files under DIR whose basename matches REGEXP."
+ (define file-rx
+ (if (regexp? regexp)
+ regexp
+ (make-regexp regexp)))
+
+ (file-system-fold (const #t)
+ (lambda (file stat result) ; leaf
+ (if (regexp-exec file-rx (basename file))
+ (cons file result)
+ result))
+ (lambda (dir stat result) ; down
+ result)
+ (lambda (dir stat result) ; up
+ result)
+ (lambda (file stat result) ; skip
+ result)
+ (lambda (file stat errno result)
+ (format (current-error-port) "find-files: ~a: ~a~%"
+ file (strerror errno))
+ #f)
+ '()
+ dir))
+
;;;
;;; Search paths.