aboutsummaryrefslogtreecommitdiff
path: root/src/property/disk.lisp
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-04-20 22:12:25 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-04-20 22:12:25 -0700
commitf694b31597f3e57ff2a4a6631aff6f76b958a1e1 (patch)
treeddd9160cf10af73c9214a3e1abb3adbe3f8428f8 /src/property/disk.lisp
parentfacd42a098ed8de8c8883b9ee0002e4b9075c16f (diff)
downloadconsfigurator-f694b31597f3e57ff2a4a6631aff6f76b958a1e1.tar.gz
add COPY-VOLUME-AND-CONTENTS
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/property/disk.lisp')
-rw-r--r--src/property/disk.lisp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/property/disk.lisp b/src/property/disk.lisp
index 8124b76..93f4466 100644
--- a/src/property/disk.lisp
+++ b/src/property/disk.lisp
@@ -60,6 +60,31 @@ plus any metadata (e.g. partition tables), this value will be ignored."))
(define-print-object-for-structlike volume)
+(defgeneric copy-volume-and-contents
+ (volume &rest initialisations &key &allow-other-keys)
+ (:documentation
+ "Make a fresh copy of VOLUME, shallowly, except for the VOLUME-CONTENTS of
+volume, which is recursively copied. Keyword arguments may be used to
+subsequently replace the copied values of some slots."))
+
+(defmethod copy-volume-and-contents
+ ((volume volume) &rest initialisations &key &allow-other-keys)
+ (let* ((class (class-of volume))
+ (copy (allocate-instance class))
+ (contents-bound-p (slot-boundp volume 'volume-contents))
+ (contents (and contents-bound-p (volume-contents volume))))
+ (dolist (slot-name (delete 'volume-contents
+ (mapcar #'closer-mop:slot-definition-name
+ (closer-mop:class-slots class))))
+ (when (slot-boundp volume slot-name)
+ (setf (slot-value copy slot-name) (slot-value volume slot-name))))
+ (when contents-bound-p
+ (setf (volume-contents copy)
+ (if (listp contents)
+ (mapcar #'copy-volume-and-contents contents)
+ (copy-volume-and-contents contents))))
+ (apply #'reinitialize-instance copy initialisations)))
+
(defmethod subvolumes-of-type ((type symbol) (volume volume))
"Recursively examine VOLUME and its VOLUME-CONTENTS and return a list of all
volumes encountered whose type is a subtype of TYPE."