mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-12-24 21:38:07 -05:00
file-systems: read-partition-{uuid,label} don't swallow ENOENT & co.
Previously, (read-partition-uuid "/does/not/exist") would return #f. With this change, a 'system-error exception is raised as expected. * gnu/build/file-systems.scm (ENOENT-safe): Clarify docstring. (partition-field-reader): Remove use of 'ENOENT-safe'. (partition-predicate): Wrap READER in 'ENOENT-safe'.
This commit is contained in:
parent
68a4ca148b
commit
e318e989b7
1 changed files with 14 additions and 15 deletions
|
@ -644,16 +644,13 @@ (define (partition? name major minor)
|
||||||
(loop parts))))))))))
|
(loop parts))))))))))
|
||||||
|
|
||||||
(define (ENOENT-safe proc)
|
(define (ENOENT-safe proc)
|
||||||
"Wrap the one-argument PROC such that ENOENT errors are caught and lead to a
|
"Wrap the one-argument PROC such that ENOENT, EIO, and ENOMEDIUM errors are
|
||||||
warning and #f as the result."
|
caught and lead to a warning and #f as the result."
|
||||||
(lambda (device)
|
(lambda (device)
|
||||||
(catch 'system-error
|
(catch 'system-error
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(proc device))
|
(proc device))
|
||||||
(lambda args
|
(lambda args
|
||||||
;; When running on the hand-made /dev,
|
|
||||||
;; 'disk-partitions' could return partitions for which
|
|
||||||
;; we have no /dev node. Handle that gracefully.
|
|
||||||
(let ((errno (system-error-errno args)))
|
(let ((errno (system-error-errno args)))
|
||||||
(cond ((= ENOENT errno)
|
(cond ((= ENOENT errno)
|
||||||
(format (current-error-port)
|
(format (current-error-port)
|
||||||
|
@ -671,11 +668,10 @@ (define (ENOENT-safe proc)
|
||||||
(define (partition-field-reader read field)
|
(define (partition-field-reader read field)
|
||||||
"Return a procedure that takes a device and returns the value of a FIELD in
|
"Return a procedure that takes a device and returns the value of a FIELD in
|
||||||
the partition superblock or #f."
|
the partition superblock or #f."
|
||||||
(let ((read (ENOENT-safe read)))
|
(lambda (device)
|
||||||
(lambda (device)
|
(let ((sblock (read device)))
|
||||||
(let ((sblock (read device)))
|
(and sblock
|
||||||
(and sblock
|
(field sblock)))))
|
||||||
(field sblock))))))
|
|
||||||
|
|
||||||
(define (read-partition-field device partition-field-readers)
|
(define (read-partition-field device partition-field-readers)
|
||||||
"Returns the value of a FIELD in the partition superblock of DEVICE or #f. It
|
"Returns the value of a FIELD in the partition superblock of DEVICE or #f. It
|
||||||
|
@ -742,11 +738,14 @@ (define read-luks-partition-uuid
|
||||||
(define (partition-predicate reader =)
|
(define (partition-predicate reader =)
|
||||||
"Return a predicate that returns true if the FIELD of partition header that
|
"Return a predicate that returns true if the FIELD of partition header that
|
||||||
was READ is = to the given value."
|
was READ is = to the given value."
|
||||||
(lambda (expected)
|
;; When running on the hand-made /dev, 'disk-partitions' could return
|
||||||
(lambda (device)
|
;; partitions for which we have no /dev node. Handle that gracefully.
|
||||||
(let ((actual (reader device)))
|
(let ((reader (ENOENT-safe reader)))
|
||||||
(and actual
|
(lambda (expected)
|
||||||
(= actual expected))))))
|
(lambda (device)
|
||||||
|
(let ((actual (reader device)))
|
||||||
|
(and actual
|
||||||
|
(= actual expected)))))))
|
||||||
|
|
||||||
(define partition-label-predicate
|
(define partition-label-predicate
|
||||||
(partition-predicate read-partition-label string=?))
|
(partition-predicate read-partition-label string=?))
|
||||||
|
|
Loading…
Reference in a new issue