mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-12-24 21:38:07 -05:00
utils: Add `find-files'.
* guix/build/utils.scm (find-files): New procedure.
This commit is contained in:
parent
c0746cc9db
commit
4c261f4169
1 changed files with 27 additions and 0 deletions
|
@ -29,6 +29,8 @@ (define-module (guix build utils)
|
|||
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 @@ (define strip-source
|
|||
#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.
|
||||
|
|
Loading…
Reference in a new issue