aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-03-27 20:43:55 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-03-27 20:45:37 -0700
commite68dfb86d1fc7292375b0bbd12ec763816272d12 (patch)
tree1f0b734a15df7b7c581a745c01abc74e7d179eb8
parent48ba34ba9f5e3dede25e3ade0c11cbed57d931d8 (diff)
downloadconsfigurator-e68dfb86d1fc7292375b0bbd12ec763816272d12.tar.gz
property/file.lisp: use WITH-CHANGE-IF-CHANGES-FILE{,-CONTENT}
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
-rw-r--r--src/property/file.lisp27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/property/file.lisp b/src/property/file.lisp
index 88f76c0..394f761 100644
--- a/src/property/file.lisp
+++ b/src/property/file.lisp
@@ -35,24 +35,27 @@ CONTENT can be a list of lines or a single string."
(declare (indent 1))
(:desc (declare (ignore content))
#?"${path} has defined content")
- (:apply (writefile path (etypecase content
- (cons (unlines content))
- (string (format nil "~A~&" content))))))
+ (:apply (with-change-if-changes-file-content (path)
+ (writefile path (etypecase content
+ (cons (unlines content))
+ (string (format nil "~A~&" content)))))))
(defprop contains-lines :posix (path lines)
"Ensure there is a file at PATH containing each of LINES once."
(:apply
- (let ((new-lines (copy-list (ensure-cons lines)))
- (existing-lines (lines (readfile path))))
- (dolist (existing-line existing-lines)
- (deletef new-lines existing-line :test #'string=))
- (writefile path (unlines (nconc existing-lines new-lines))))))
+ (with-change-if-changes-file-content (path)
+ (let ((new-lines (copy-list (ensure-cons lines)))
+ (existing-lines (lines (readfile path))))
+ (dolist (existing-line existing-lines)
+ (deletef new-lines existing-line :test #'string=))
+ (writefile path (unlines (nconc existing-lines new-lines)))))))
(defprop has-mode :posix (path mode)
"Ensure that a file has a particular numeric mode."
(:desc (format nil "~A has mode ~O" path mode))
(:apply
- (mrun (format nil "chmod ~O ~A" mode path))))
+ (with-change-if-changes-file (path)
+ (mrun (format nil "chmod ~O ~A" mode path)))))
(defprop does-not-exist :posix (&rest paths)
"Ensure that files do not exist."
@@ -67,7 +70,8 @@ CONTENT can be a list of lines or a single string."
(declare (ignore destination))
(require-data iden1 iden2))
(:apply
- (writefile destination (get-data-stream iden1 iden2))))
+ (with-change-if-changes-file-content (destination)
+ (writefile destination (get-data-stream iden1 iden2)))))
(defprop host-data-uploaded :posix (destination)
(:hostattrs
@@ -80,7 +84,8 @@ CONTENT can be a list of lines or a single string."
(declare (ignore destination))
(require-data iden1 iden2))
(:apply
- (writefile destination (get-data-stream iden1 iden2) :mode #o600)))
+ (with-change-if-changes-file-content (destination)
+ (writefile destination (get-data-stream iden1 iden2) :mode #o600))))
(defprop host-secret-uploaded :posix (destination)
(:hostattrs