guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

01/02: utils: Add 'false-if-file-not-found'.


From: Ludovic Courtès
Subject: 01/02: utils: Add 'false-if-file-not-found'.
Date: Wed, 14 Mar 2018 07:17:33 -0400 (EDT)

civodul pushed a commit to branch core-updates
in repository guix.

commit 5c6391b33acaaae75746f6ae30089d4aec14c349
Author: Ludovic Courtès <address@hidden>
Date:   Sun Mar 11 22:04:12 2018 +0100

    utils: Add 'false-if-file-not-found'.
    
    * guix/build/utils.scm (false-if-file-not-found): New macro.
---
 guix/build/utils.scm | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/guix/build/utils.scm b/guix/build/utils.scm
index d7ed3d5..ab309aa 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 
<address@hidden>
+;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018 Ludovic Courtès 
<address@hidden>
 ;;; Copyright © 2013 Andreas Enge <address@hidden>
 ;;; Copyright © 2013 Nikita Karetnikov <address@hidden>
 ;;; Copyright © 2015 Mark H Weaver <address@hidden>
@@ -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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]