diff mbox series

[bug#49169,09/11] utils: 'edit-expression' modifies the file only if necessary.

Message ID 20210622090830.15561-9-ludo@gnu.org
State Accepted
Headers show
Series Removing input labels from package definitions | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Ludovic Courtès June 22, 2021, 9:08 a.m. UTC
* guix/utils.scm (edit-expression): Check whether STR* equals STR.
---
 guix/utils.scm | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/guix/utils.scm b/guix/utils.scm
index f8f6672bb1..e6d0761679 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -423,17 +423,19 @@  This procedure returns #t on success."
                            (port-encoding in)))
                  (post-bv (get-bytevector-all in))
                  (str*    (proc str)))
-            ;; Verify the edited expression is still a scheme expression.
-            (call-with-input-string str* read)
-            ;; Update the file with edited expression.
-            (with-atomic-file-output file
-              (lambda (out)
-                (put-bytevector out pre-bv)
-                (display str* out)
-                ;; post-bv maybe the end-of-file object.
-                (when (not (eof-object? post-bv))
-                  (put-bytevector out post-bv))
-                #t))))))))
+            ;; Modify FILE only if there are changes.
+            (unless (string=? str* str)
+              ;; Verify the edited expression is still a scheme expression.
+              (call-with-input-string str* read)
+              ;; Update the file with edited expression.
+              (with-atomic-file-output file
+                (lambda (out)
+                  (put-bytevector out pre-bv)
+                  (display str* out)
+                  ;; post-bv maybe the end-of-file object.
+                  (when (not (eof-object? post-bv))
+                    (put-bytevector out post-bv))
+                  #t)))))))))
 
 
 ;;;