[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug#49169] [PATCH v2 09/16] utils: 'edit-expression' modifies the file
From: |
Ludovic Courtès |
Subject: |
[bug#49169] [PATCH v2 09/16] utils: 'edit-expression' modifies the file only if necessary. |
Date: |
Wed, 30 Jun 2021 22:48:25 +0200 |
* guix/utils.scm (edit-expression): Check whether STR* equals STR.
---
guix/utils.scm | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)
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)))))))))
;;;
--
2.32.0
- [bug#49169] [PATCH v2 04/16] packages: Add 'lookup-package-input' & co., (continued)
- [bug#49169] [PATCH v2 04/16] packages: Add 'lookup-package-input' & co., Ludovic Courtès, 2021/06/30
- [bug#49169] [PATCH v2 05/16] packages: Add 'modify-inputs'., Ludovic Courtès, 2021/06/30
- [bug#49169] [PATCH v2 07/16] utils: 'edit-expression' no longer leaks file ports., Ludovic Courtès, 2021/06/30
- [bug#49169] [PATCH v2 06/16] gnu: Change inputs of core packages to plain lists., Ludovic Courtès, 2021/06/30
- [bug#49169] [PATCH v2 10/16] utils: 'edit-expression' copies part of the original source map., Ludovic Courtès, 2021/06/30
- [bug#49169] [PATCH v2 12/16] packages: 'hidden-package' inherits the original package location., Ludovic Courtès, 2021/06/30
- [bug#49169] [PATCH v2 13/16] import: pypi: Emit new-style package inputs., Ludovic Courtès, 2021/06/30
- [bug#49169] [PATCH v2 14/16] import: cran: Emit new-style package inputs., Ludovic Courtès, 2021/06/30
- [bug#49169] [PATCH v2 15/16] import: print: Emit new-style package inputs when possible., Ludovic Courtès, 2021/06/30
- [bug#49169] [PATCH v2 08/16] utils: Add 'go-to-location' with source location caching., Ludovic Courtès, 2021/06/30
- [bug#49169] [PATCH v2 09/16] utils: 'edit-expression' modifies the file only if necessary.,
Ludovic Courtès <=
- [bug#49169] [PATCH v2 11/16] Add 'guix style'., Ludovic Courtès, 2021/06/30
- [bug#49169] [PATCH v2 16/16] import: elpa: Emit new-style package inputs., Ludovic Courtès, 2021/06/30