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.
This commit is contained in:
Ludovic Courtès 2016-04-17 00:05:06 +02:00
parent e9dffec126
commit 2447335625
1 changed files with 20 additions and 16 deletions

View File

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