aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-05-31 11:39:17 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-05-31 14:17:45 -0700
commitea65968c79bf0709664081e4c116dee0d9c536ab (patch)
treed5020ad301052db98d873584565352089cbcbe7a
parent47aa65619025242b26cf3473efe25f88c24ae323 (diff)
downloadconsfigurator-ea65968c79bf0709664081e4c116dee0d9c536ab.tar.gz
add & use WORDS, UNWORDS
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
-rw-r--r--src/package.lisp2
-rw-r--r--src/property/file.lisp42
-rw-r--r--src/property/fstab.lisp5
-rw-r--r--src/util.lisp6
4 files changed, 29 insertions, 26 deletions
diff --git a/src/package.lisp b/src/package.lisp
index f9a5afa..163ad31 100644
--- a/src/package.lisp
+++ b/src/package.lisp
@@ -67,6 +67,8 @@
;; util.lisp
#:lines
#:unlines
+ #:words
+ #:unwords
#:noop
#:symbol-named
#:memstring=
diff --git a/src/property/file.lisp b/src/property/file.lisp
index 4af2e27..a54d38c 100644
--- a/src/property/file.lisp
+++ b/src/property/file.lisp
@@ -439,25 +439,23 @@ not NO-SOURCE and the corresponding member of ENTRIES is STRING= to either
NO-SOURCE or \"PLACEHOLDER\", use the existing field value."
(let ((unknown (list no-source "PLACEHOLDER"))
(pending (make-hash-table :test #'equal)))
- (flet ((fields (entry)
- (remove "" (split-string entry) :test #'string=)))
- (dolist (entry entries)
- (setf (gethash (nth target (fields entry)) pending) entry))
- (map-file-lines
- file
- (lambda (lines)
- (loop for line in lines
- for line-fields = (fields line)
- for line-source = (nth source line-fields)
- and line-target = (nth target line-fields)
- for entry = (when-let* ((entry (gethash line-target pending))
- (fields (fields entry)))
- (when (and (member (nth source fields)
- unknown :test #'string=)
- (not (string= line-source no-source)))
- (setf (nth source fields) line-source))
- (format nil "~{~A~^ ~}" fields))
- if entry
- collect it into accum and do (remhash line-target pending)
- else collect line into accum
- finally (return (nconc accum (hash-table-values pending)))))))))
+ (dolist (entry entries)
+ (setf (gethash (nth target (words entry)) pending) entry))
+ (map-file-lines
+ file
+ (lambda (lines)
+ (loop for line in lines
+ for line-fields = (words line)
+ for line-source = (nth source line-fields)
+ and line-target = (nth target line-fields)
+ for entry = (when-let* ((entry (gethash line-target pending))
+ (fields (words entry)))
+ (when (and (member (nth source fields)
+ unknown :test #'string=)
+ (not (string= line-source no-source)))
+ (setf (nth source fields) line-source))
+ (format nil "~{~A~^ ~}" fields))
+ if entry
+ collect it into accum and do (remhash line-target pending)
+ else collect line into accum
+ finally (return (nconc accum (hash-table-values pending))))))))
diff --git a/src/property/fstab.lisp b/src/property/fstab.lisp
index 540efc4..c150968 100644
--- a/src/property/fstab.lisp
+++ b/src/property/fstab.lisp
@@ -74,10 +74,7 @@ member of ENTRIES is \"none\", or \"PLACEHOLDER\", use the existing field value.
This makes it easy to update mount options without having to specify the
partition or filesystem UUID in your consfig."
(:desc
- (let ((mount-points
- (loop for entry in entries
- collect (cadr
- (remove "" (split-string entry) :test #'string=)))))
+ (let ((mount-points (mapcar (compose #'cadr #'words) entries)))
(format nil "fstab entr~@P for ~{~A~^, ~}"
(length mount-points) mount-points)))
(:apply (file:update-unix-table #P"/etc/fstab" 0 1 entries)))
diff --git a/src/util.lisp b/src/util.lisp
index 3260de0..9d50a17 100644
--- a/src/util.lisp
+++ b/src/util.lisp
@@ -29,6 +29,12 @@
(defun unlines (lines)
(format nil "~{~A~%~}" lines))
+(defun words (text)
+ (remove "" (split-string text) :test #'string=))
+
+(defun unwords (words)
+ (format nil "~{~A~^ ~}" words))
+
(defmacro symbol-named (name symbol)
`(and (symbolp ,symbol)
(string= (symbol-name ',name) (symbol-name ,symbol))))