From 23b372b7a38c1f9ac761b7d5550008f42844600f Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Wed, 19 May 2021 16:49:51 -0700 Subject: FILE:CONTAINS-LINES: avoid writing file if lines already present Signed-off-by: Sean Whitton --- src/property/file.lisp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/property/file.lisp') 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." -- cgit v1.2.3