summaryrefslogtreecommitdiff
path: root/guix/build/utils.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2018-03-11 22:04:12 +0100
committerLudovic Courtès <ludo@gnu.org>2018-03-11 22:04:39 +0100
commit5c6391b33acaaae75746f6ae30089d4aec14c349 (patch)
tree34d09d3b0fe68b08c1539212e817bb0756f48785 /guix/build/utils.scm
parent5e268faf85c60b5e12cbc742c5e3bf3d20771cb9 (diff)
utils: Add 'false-if-file-not-found'.
* guix/build/utils.scm (false-if-file-not-found): New macro.
Diffstat (limited to 'guix/build/utils.scm')
-rw-r--r--guix/build/utils.scm12
1 files changed, 11 insertions, 1 deletions
diff --git a/guix/build/utils.scm b/guix/build/utils.scm
index d7ed3d5177..ab309aa0df 100644
--- a/guix/build/utils.scm
+++ b/guix/build/utils.scm
@@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2013 Andreas Enge <andreas@enge.fr>
;;; Copyright © 2013 Nikita Karetnikov <nikita@karetnikov.org>
;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
@@ -61,6 +61,7 @@
delete-file-recursively
file-name-predicate
find-files
+ false-if-file-not-found
search-path-as-list
set-path-environment-variable
@@ -396,6 +397,15 @@ also be included. If FAIL-ON-ERROR? is true, raise an exception upon error."
stat)
string<?)))
+(define-syntax-rule (false-if-file-not-found exp)
+ "Evaluate EXP but return #f if it raises to 'system-error with ENOENT."
+ (catch 'system-error
+ (lambda () exp)
+ (lambda args
+ (if (= ENOENT (system-error-errno args))
+ #f
+ (apply throw args)))))
+
;;;
;;; Search paths.