aboutsummaryrefslogtreecommitdiff
path: root/src/property/disk.lisp
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-05-31 12:51:17 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-05-31 14:18:16 -0700
commit33f17a22ce74eb605da95722a40516f4450f639c (patch)
treebb8a7399e2da339ecf613a19ce50c19866776cda /src/property/disk.lisp
parentea65968c79bf0709664081e4c116dee0d9c536ab (diff)
downloadconsfigurator-33f17a22ce74eb605da95722a40516f4450f639c.tar.gz
DISK:CREATE-VOLUMES-AND-CONTENTS: add FILES argument; make a DEFUN
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/property/disk.lisp')
-rw-r--r--src/property/disk.lisp55
1 files changed, 27 insertions, 28 deletions
diff --git a/src/property/disk.lisp b/src/property/disk.lisp
index f82460e..618c4bc 100644
--- a/src/property/disk.lisp
+++ b/src/property/disk.lisp
@@ -713,34 +713,33 @@ must not be modified."
(mapc #'close-volume (get-connattr :opened-volumes)))))
:args (cdr propapp)))
-(defgeneric create-volumes-and-contents (volumes)
- (:documentation
- "Where each of VOLUMES is a VOLUME which may be created by calling
-CREATE-VOLUME with NIL as the second argument, recursively create each of
-VOLUMES and any contents thereof.
-**THIS METHOD UNCONDITIONALLY FORMATS DISKS, POTENTIALLY DESTROYING DATA.**")
- (:method (volumes)
- (let (opened-volumes)
- (labels
- ((create-volume-and-contents (volume file)
- (create-volume volume file)
- (when (slot-boundp volume 'volume-contents)
- (multiple-value-bind (opened opened-contents)
- (open-volume volume file)
- (setq opened-volumes
- (append opened-contents (cons opened opened-volumes)))
- (if opened-contents
- (dolist (opened-volume opened-contents)
- (when (slot-boundp opened-volume 'volume-contents)
- (create-volume-and-contents
- (volume-contents opened-volume)
- (device-file opened-volume))))
- (create-volume-and-contents
- (volume-contents opened) (device-file opened)))))))
- (unwind-protect
- (mapc (rcurry #'create-volume-and-contents nil) volumes)
- (mrun "sync")
- (mapc #'close-volume opened-volumes))))))
+(defun create-volumes-and-contents (volumes &optional files)
+ "Where each of VOLUMES is a VOLUME which may be created by calling
+CREATE-VOLUME with the corresponding entry of FILES, or NIL, as a second
+argument, recursively create each of VOLUMES and any contents thereof.
+**THIS FUNCTION UNCONDITIONALLY FORMATS DISKS, POTENTIALLY DESTROYING DATA.**"
+ (let (opened-volumes)
+ (labels
+ ((create-volume-and-contents (volume file)
+ (create-volume volume file)
+ (when (slot-boundp volume 'volume-contents)
+ (multiple-value-bind (opened opened-contents)
+ (open-volume volume file)
+ (setq opened-volumes
+ (append opened-contents (cons opened opened-volumes)))
+ (if opened-contents
+ (dolist (opened-volume opened-contents)
+ (when (slot-boundp opened-volume 'volume-contents)
+ (create-volume-and-contents
+ (volume-contents opened-volume)
+ (device-file opened-volume))))
+ (create-volume-and-contents
+ (volume-contents opened) (device-file opened)))))))
+ (unwind-protect
+ (mapc #'create-volume-and-contents
+ volumes (loop repeat (length volumes) collect (pop files)))
+ (mrun "sync")
+ (mapc #'close-volume opened-volumes)))))
;;;; Properties