aboutsummaryrefslogtreecommitdiff
path: root/src/property/disk.lisp
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-04-16 19:23:40 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-04-16 20:35:23 -0700
commit49602a3696384425b6c305e16e69b2ee9903f4be (patch)
tree6abd8c3f422702eef164bce4981d4beee999ec81 /src/property/disk.lisp
parent6de8c65930112143f77e8412aa60cf574e418ddb (diff)
downloadconsfigurator-49602a3696384425b6c305e16e69b2ee9903f4be.tar.gz
add WITH-THESE-OPEN-VOLUMES macro property combinator
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/property/disk.lisp')
-rw-r--r--src/property/disk.lisp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/property/disk.lisp b/src/property/disk.lisp
index 9e8e55f..ecc26c8 100644
--- a/src/property/disk.lisp
+++ b/src/property/disk.lisp
@@ -503,6 +503,42 @@ populate /etc/fstab and /etc/crypttab. Do not modify this list."
(unwind-protect (progn ,@forms)
,(with-mount-below `(mapc #'close-volume ,opened-volumes)))))))
+(defmacro with-these-open-volumes
+ ((volumes &key (mount-below nil mount-below-supplied-p)) &body propapps)
+ "Macro property combinator. Where each of VOLUMES is a VOLUME which may be
+opened by calling OPEN-VOLUME with NIL as the second argument, recursively
+open each of VOLUMES and any contents thereof, apply PROPAPPS, and close all
+volumes that were opened.
+
+MOUNT-BELOW specifies a pathname to prefix to mount points when opening
+FILESYSTEM volumes. During the application of PROPAPPS, all :OPENED-VOLUMES
+hostattrs are replaced with a list of the volumes that were opened; this list
+must not be modified."
+ `(with-these-open-volumes*
+ ,volumes
+ ,(if (cdr propapps) `(eseqprops ,@propapps) (car propapps))
+ ,@(and mount-below-supplied-p `(:mount-below ,mount-below))))
+
+(define-function-property-combinator with-these-open-volumes*
+ (volumes propapp &key (mount-below nil mount-below-supplied-p))
+ (:retprop
+ :type (propapptype propapp)
+ :hostattrs (get (car propapp) 'hostattrs)
+ :apply
+ (lambda (&rest ignore)
+ (declare (ignore ignore))
+ (let ((opened-volumes
+ (apply #'open-volumes-and-contents
+ `(,volumes ,@(and mount-below-supplied-p
+ `(:mount-below ,mount-below))))))
+ (unwind-protect-in-parent
+ (with-replace-hostattrs (:opened-volumes)
+ (apply #'push-hostattrs
+ :opened-volumes opened-volumes)
+ (propappapply propapp))
+ (with-mount-below (mapc #'close-volume opened-volumes)))))
+ :args (cdr propapp)))
+
(defmethod create-volume-and-contents ((volume volume) file)
"Recursively create VOLUME and its contents, on or at FILE.
**THIS METHOD UNCONDITIONALLY FORMATS DISKS, POTENTIALLY DESTROYING DATA**"