~ruther/guix-local

4c261f4169b9da6b8a04d420422426e5548feac4 — Ludovic Courtès 13 years ago c0746cc
utils: Add `find-files'.

* guix/build/utils.scm (find-files): New procedure.
1 files changed, 27 insertions(+), 0 deletions(-)

M guix/build/utils.scm
M guix/build/utils.scm => guix/build/utils.scm +27 -0
@@ 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.