mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2025-01-21 18:19:15 -05:00
utils: 'edit-expression' modifies the file only if necessary.
* guix/utils.scm (edit-expression): Check whether STR* equals STR.
This commit is contained in:
parent
ef1432f064
commit
f05433f208
1 changed files with 13 additions and 11 deletions
|
@ -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)))))))))
|
||||
|
||||
|
||||
;;;
|
||||
|
|
Loading…
Reference in a new issue