[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
08/09: image: Add sanitizers for 'format' and 'partition-table-type'.
From: |
guix-commits |
Subject: |
08/09: image: Add sanitizers for 'format' and 'partition-table-type'. |
Date: |
Fri, 1 Jul 2022 06:27:36 -0400 (EDT) |
civodul pushed a commit to branch master
in repository guix.
commit 0dab106a6af36eaebfd533d3e38c1275deb85935
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Fri Jul 1 12:06:39 2022 +0200
image: Add sanitizers for 'format' and 'partition-table-type'.
This allows common mistakes to be diagnosed early.
* gnu/image.scm (define-set-sanitizer): New macro.
(validate-image-format, validate-partition-table-type): New sanitizers.
(<image>)[format, partition-table-type]: Add 'sanitize' property.
---
gnu/image.scm | 28 ++++++++++++++++++++++++++--
1 file changed, 26 insertions(+), 2 deletions(-)
diff --git a/gnu/image.scm b/gnu/image.scm
index e347089b34..486c02aadc 100644
--- a/gnu/image.scm
+++ b/gnu/image.scm
@@ -19,6 +19,10 @@
(define-module (gnu image)
#:use-module (guix platform)
#:use-module (guix records)
+ #:use-module (guix diagnostics)
+ #:use-module (guix i18n)
+ #:use-module (srfi srfi-34)
+ #:use-module (srfi srfi-35)
#:export (partition
partition?
partition-device
@@ -77,12 +81,31 @@
;;; Image record.
;;;
+(define-syntax-rule (define-set-sanitizer name field set)
+ "Define NAME as a procedure or macro that raises an error if passed a value
+that is not in SET, mentioning FIELD in the error message."
+ (define-with-syntax-properties (name (value properties))
+ (unless (memq value 'set)
+ (raise
+ (make-compound-condition
+ (condition
+ (&error-location
+ (location (source-properties->location properties))))
+ (formatted-message (G_ "~s: invalid '~a' value") value 'field))))
+ value))
+
+(define-set-sanitizer validate-image-format format
+ (disk-image compressed-qcow2 docker iso9660))
+(define-set-sanitizer validate-partition-table-type partition-table-type
+ (mbr gpt))
+
(define-record-type* <image>
image make-image
image?
(name image-name ;symbol
(default #f))
- (format image-format) ;symbol
+ (format image-format ;symbol
+ (sanitize validate-image-format))
(platform image-platform ;<platform>
(default #f))
(size image-size ;size in bytes as integer
@@ -90,7 +113,8 @@
(operating-system image-operating-system ;<operating-system>
(default #f))
(partition-table-type image-partition-table-type ; 'mbr or 'gpt
- (default 'mbr))
+ (default 'mbr)
+ (sanitize validate-partition-table-type))
(partitions image-partitions ;list of <partition>
(default '()))
(compression? image-compression? ;boolean
- branch master updated (b5c6062bce -> 741895676b), guix-commits, 2022/07/01
- 03/09: services: root-file-system: Cleanly unmount upon shutdown., guix-commits, 2022/07/01
- 08/09: image: Add sanitizers for 'format' and 'partition-table-type'.,
guix-commits <=
- 02/09: file-systems: Add 'cleanly-unmounted-ext2?'., guix-commits, 2022/07/01
- 06/09: image: Avoid use of the deprecated 'gpt' option of genimage., guix-commits, 2022/07/01
- 04/09: image: 'system-image' throws when given an incorrect image format., guix-commits, 2022/07/01
- 05/09: image: Add default value for partition initializer., guix-commits, 2022/07/01
- 01/09: gnu: texlive-fmtcount: Add proper 'license' value., guix-commits, 2022/07/01
- 07/09: image: Raise an error when an image lacks a bootable partition., guix-commits, 2022/07/01
- 09/09: tests: Add sanitizer test., guix-commits, 2022/07/01