utils: 'edit-expression' modifies the file only if necessary.

* guix/utils.scm (edit-expression): Check whether STR* equals STR.
This commit is contained in:
Ludovic Courtès 2021-06-21 13:56:59 +02:00
parent ef1432f064
commit f05433f208
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5

View file

@ -423,17 +423,19 @@ (define column (assq-ref source-properties 'column))
(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)))))))))
;;;