aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-05-19 16:49:51 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-05-19 16:49:51 -0700
commit23b372b7a38c1f9ac761b7d5550008f42844600f (patch)
treede7f8c28c045ee0718d86062c9a31513a4881966
parent8dc928c2ca58e6116f6a35573bd6c97433f12400 (diff)
downloadconsfigurator-23b372b7a38c1f9ac761b7d5550008f42844600f.tar.gz
FILE:CONTAINS-LINES: avoid writing file if lines already present
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
-rw-r--r--src/property/file.lisp15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/property/file.lisp b/src/property/file.lisp
index ff2aa3f..9d23446 100644
--- a/src/property/file.lisp
+++ b/src/property/file.lisp
@@ -52,13 +52,14 @@ CONTENT can be a list of lines or a single string."
(defprop contains-lines :posix (path &rest lines)
"Ensure there is a file at PATH containing each of LINES once."
(:apply
- (with-change-if-changes-file-content (path)
- (let ((new-lines (copy-list (ensure-cons lines)))
- (existing-lines (and (remote-exists-p path)
- (lines (readfile path)))))
- (dolist (existing-line existing-lines)
- (deletef new-lines existing-line :test #'string=))
- (writefile path (unlines (nconc existing-lines new-lines)))))))
+ (let ((new-lines (copy-list (ensure-cons lines)))
+ (existing-lines (and (remote-exists-p path)
+ (lines (readfile path)))))
+ (dolist (existing-line existing-lines)
+ (deletef new-lines existing-line :test #'string=))
+ (if new-lines
+ (writefile path (unlines (nconc existing-lines new-lines)))
+ :no-change))))
(defprop lacks-lines :posix (path &rest lines)
"If there is a file at PATH, ensure it does not contain any of LINES."