utils: 'edit-expression' no longer leaks file ports.

* guix/utils.scm (edit-expression): Use 'call-with-input-file' to make
sure IN gets closed.
This commit is contained in:
Ludovic Courtès 2021-06-19 22:00:44 +02:00
parent 2f73ea3487
commit 4dcc606766
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5

View File

@ -342,12 +342,14 @@ a list of command-line arguments passed to the compression program."
be a procedure that takes the original expression in string and returns a new
one. ENCODING will be used to interpret all port I/O, it default to UTF-8.
This procedure returns #t on success."
(define file (assq-ref source-properties 'filename))
(define line (assq-ref source-properties 'line))
(define column (assq-ref source-properties 'column))
(with-fluids ((%default-port-encoding encoding))
(let* ((file (assq-ref source-properties 'filename))
(line (assq-ref source-properties 'line))
(column (assq-ref source-properties 'column))
(in (open-input-file file))
;; The start byte position of the expression.
(call-with-input-file file
(lambda (in)
(let* ( ;; The start byte position of the expression.
(start (begin (while (not (and (= line (port-line in))
(= column (port-column in))))
(when (eof-object? (read-char in))
@ -373,7 +375,7 @@ This procedure returns #t on success."
;; post-bv maybe the end-of-file object.
(when (not (eof-object? post-bv))
(put-bytevector out post-bv))
#t))))))
#t))))))))
;;;