[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
01/02: utils: find-files: Add DIRECTORIES? and FAIL-ON-ERROR? arguments.
From: |
Mark H. Weaver |
Subject: |
01/02: utils: find-files: Add DIRECTORIES? and FAIL-ON-ERROR? arguments. |
Date: |
Sun, 06 Sep 2015 21:26:45 +0000 |
mhw pushed a commit to branch core-updates
in repository guix.
commit f4ae827e26b1bbbd47ac05bb2a4278d5c61c828e
Author: Mark H Weaver <address@hidden>
Date: Sun Sep 6 12:24:08 2015 -0400
utils: find-files: Add DIRECTORIES? and FAIL-ON-ERROR? arguments.
* guix/build/utils.scm (find-files): Add DIRECTORIES? and FAIL-ON-ERROR?
keyword arguments.
---
guix/build/utils.scm | 15 ++++++++++++---
1 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/guix/build/utils.scm b/guix/build/utils.scm
index 2720742..9719296 100644
--- a/guix/build/utils.scm
+++ b/guix/build/utils.scm
@@ -2,6 +2,7 @@
;;; Copyright © 2012, 2013, 2014, 2015 Ludovic Courtès <address@hidden>
;;; Copyright © 2013 Andreas Enge <address@hidden>
;;; Copyright © 2013 Nikita Karetnikov <address@hidden>
+;;; Copyright © 2015 Mark H Weaver <address@hidden>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -316,13 +317,16 @@ name matches REGEXP."
(regexp-exec file-rx (basename file)))))
(define* (find-files dir #:optional (pred (const #t))
- #:key (stat lstat))
+ #:key (stat lstat)
+ directories?
+ fail-on-error?)
"Return the lexicographically sorted list of files under DIR for which PRED
returns true. PRED is passed two arguments: the absolute file name, and its
stat buffer; the default predicate always returns true. PRED can also be a
regular expression, in which case it is equivalent to (file-name-predicate
PRED). STAT is used to obtain file information; using 'lstat' means that
-symlinks are not followed."
+symlinks are not followed. If DIRECTORIES? is true, then directories will
+also be included. If FAIL-ON-ERROR? is true, raise an exception upon error."
(let ((pred (if (procedure? pred)
pred
(file-name-predicate pred))))
@@ -333,7 +337,10 @@ symlinks are not followed."
(cons file result)
result))
(lambda (dir stat result) ; down
- result)
+ (if (and directories?
+ (pred dir stat))
+ (cons dir result)
+ result))
(lambda (dir stat result) ; up
result)
(lambda (file stat result) ; skip
@@ -341,6 +348,8 @@ symlinks are not followed."
(lambda (file stat errno result)
(format (current-error-port) "find-files: ~a:
~a~%"
file (strerror errno))
+ (when fail-on-error?
+ (error "find-files failed"))
result)
'()
dir