me
/
guix
Archived
1
0
Fork 0

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

* guix/utils.scm (edit-expression): Check whether STR* equals STR.
master
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
1 changed files with 13 additions and 11 deletions

View File

@ -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)))))))))
;;;