guix-commits
[Top][All Lists]
Advanced

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

03/04: file-systems: Separate ENOENT catching from ext2 superblock reads


From: Ludovic Courtès
Subject: 03/04: file-systems: Separate ENOENT catching from ext2 superblock reads.
Date: Sat, 16 Apr 2016 23:24:34 +0000

civodul pushed a commit to branch master
in repository guix.

commit 2447335625fb0b8fcb9aae0852d86eb6310188ce
Author: Ludovic Courtès <address@hidden>
Date:   Sun Apr 17 00:05:06 2016 +0200

    file-systems: Separate ENOENT catching from ext2 superblock reads.
    
    * gnu/build/file-systems.scm (ENOENT-safe): New procedure.
    (read-ext2-superblock*): Rewrite in terms of it.
---
 gnu/build/file-systems.scm |   36 ++++++++++++++++++++----------------
 1 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm
index 58ccf59..9af4f5a 100644
--- a/gnu/build/file-systems.scm
+++ b/gnu/build/file-systems.scm
@@ -167,22 +167,26 @@ if DEVICE does not contain an ext2 file system."
                      (loop (cons name parts))
                      (loop parts))))))))))
 
-(define (read-ext2-superblock* device)
-  "Like 'read-ext2-superblock', but return #f when DEVICE does not exist
-instead of throwing an exception."
-  (catch 'system-error
-    (lambda ()
-      (read-ext2-superblock device))
-    (lambda args
-      ;; When running on the hand-made /dev,
-      ;; 'disk-partitions' could return partitions for which
-      ;; we have no /dev node.  Handle that gracefully.
-      (if (= ENOENT (system-error-errno args))
-          (begin
-            (format (current-error-port)
-                    "warning: device '~a' not found~%" device)
-            #f)
-          (apply throw args)))))
+(define (ENOENT-safe proc)
+  "Wrap the one-argument PROC such that ENOENT errors are caught and lead to a
+warning and #f as the result."
+  (lambda (device)
+    (catch 'system-error
+      (lambda ()
+        (proc device))
+      (lambda args
+        ;; When running on the hand-made /dev,
+        ;; 'disk-partitions' could return partitions for which
+        ;; we have no /dev node.  Handle that gracefully.
+        (if (= ENOENT (system-error-errno args))
+            (begin
+              (format (current-error-port)
+                      "warning: device '~a' not found~%" device)
+              #f)
+            (apply throw args))))))
+
+(define read-ext2-superblock*
+  (ENOENT-safe read-ext2-superblock))
 
 (define (partition-predicate field =)
   "Return a predicate that returns true if the FIELD of an ext2 superblock is



reply via email to

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