[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug#49169] [PATCH 09/11] utils: 'edit-expression' modifies the file onl
From: |
Ludovic Courtès |
Subject: |
[bug#49169] [PATCH 09/11] utils: 'edit-expression' modifies the file only if necessary. |
Date: |
Tue, 22 Jun 2021 11:08:28 +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 00/11] Removing input labels from package definitions, Ludovic Courtès, 2021/06/22
- [bug#49169] [PATCH 01/11] records: Support field sanitizers., Ludovic Courtès, 2021/06/22
- [bug#49169] [PATCH 02/11] packages: Allow inputs to be plain package lists., Ludovic Courtès, 2021/06/22
- [bug#49169] [PATCH 04/11] packages: Add 'lookup-package-input' & co., Ludovic Courtès, 2021/06/22
- [bug#49169] [PATCH 07/11] utils: 'edit-expression' no longer leaks file ports., Ludovic Courtès, 2021/06/22
- [bug#49169] [PATCH 03/11] lint: Add 'input-labels' checker., Ludovic Courtès, 2021/06/22
- [bug#49169] [PATCH 05/11] packages: Add 'modify-inputs'., Ludovic Courtès, 2021/06/22
- [bug#49169] [PATCH 09/11] utils: 'edit-expression' modifies the file only if necessary.,
Ludovic Courtès <=
- [bug#49169] [PATCH 06/11] gnu: Change inputs of core packages to plain lists., Ludovic Courtès, 2021/06/22
- [bug#49169] [PATCH 08/11] utils: Add 'go-to-location' with source location caching., Ludovic Courtès, 2021/06/22
- [bug#49169] [PATCH 10/11] utils: 'edit-expression' copies part of the original source map., Ludovic Courtès, 2021/06/22
- [bug#49169] [PATCH 11/11] Add 'guix style'., Ludovic Courtès, 2021/06/22
- [bug#49169] [PATCH 00/11] Removing input labels from package definitions, Ludovic Courtès, 2021/06/22
- [bug#49169] [PATCH 00/11] Removing input labels from package definitions, Ludovic Courtès, 2021/06/27
- [bug#49169] [PATCH v2 00/16] Removing input labels from package definitions, Ludovic Courtès, 2021/06/30