GNU bug report logs -
#75588
[PATCH] guix: utils: Delete temporary output files.
Previous Next
Reported by: Kierin Bell <fernseed <at> fernseed.me>
Date: Wed, 15 Jan 2025 16:53:02 UTC
Severity: normal
Tags: patch
Done: Kierin Bell <fernseed <at> fernseed.me>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 75588 in the body.
You can then email your comments to 75588 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
andreas <at> enge.fr, janneke <at> gnu.org, ludo <at> gnu.org, guix-patches <at> gnu.org
:
bug#75588
; Package
guix-patches
.
(Wed, 15 Jan 2025 16:53:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Kierin Bell <fernseed <at> fernseed.me>
:
New bug report received and forwarded. Copy sent to
andreas <at> enge.fr, janneke <at> gnu.org, ludo <at> gnu.org, guix-patches <at> gnu.org
.
(Wed, 15 Jan 2025 16:53:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
* guix/build/utils.scm (call-with-temporary-output-file): Delete and
pass procedure the actual temporary file name, not the template name.
Change-Id: Id8e5da55444195fcee91517cf63ec8ebd20942e5
---
This change will trigger *many* rebuilds, I think because
'call-with-temporary-output-file' is used by 'download-to-store'.
This patch fixes a bug that causes: 1) the procedure passed to
'call-with-temporary-output-file' to always be called with the file name
template string "/guix-file.XXXXXX" rather than the name of the created
temporary file; and 2) the temporary file to persist rather than being
deleted.
Unless I'm missing something, Guix is creating temporary files without
deleting them and nobody is noticing.
Also, more importantly, it's a miracle that nothing has broken because
of issue #1. Apparently, in most applications in the Guix code base, the
procedures passed to this function discard their second argument (the
port) and only use the first argument (what should be the file name).
After a quick search, the only exceptions that I could find are some
unit tests and 'call-with-luks-key-file' in (gnu installer parted). I'm
not sure how this hasn't caused issues there.
I haven't had time to test this yet, because it triggers so many
rebuilds.
guix/build/utils.scm | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/guix/build/utils.scm b/guix/build/utils.scm
index 94714bf397..dda8fb9d82 100644
--- a/guix/build/utils.scm
+++ b/guix/build/utils.scm
@@ -287,15 +287,16 @@ (define (call-with-temporary-output-file proc)
call."
(let* ((directory (or (getenv "TMPDIR") "/tmp"))
(template (string-append directory "/guix-file.XXXXXX"))
- (out (mkstemp! template)))
+ (out (mkstemp! template))
+ (filename (port-filename out)))
(dynamic-wind
(lambda ()
#t)
(lambda ()
- (proc template out))
+ (proc filename out))
(lambda ()
(false-if-exception (close out))
- (false-if-exception (delete-file template))))))
+ (false-if-exception (delete-file filename))))))
(define (call-with-ascii-input-file file proc)
"Open FILE as an ASCII or binary file, and pass the resulting port to
base-commit: b696658ee8e0655b17f5d26e024956b5148e36d6
--
2.47.1
Information forwarded
to
guix-patches <at> gnu.org
:
bug#75588
; Package
guix-patches
.
(Wed, 15 Jan 2025 19:42:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 75588 <at> debbugs.gnu.org (full text, mbox):
help-debbugs <at> gnu.org (GNU bug Tracking System) writes:
So this bug should be canceled! It doesn't actually change the behavior
of the function in any way (though it may making it easier to read for
people not familiar with 'mkstemp!').
I did find a corner-case where temporary files created by
'call-with-temporary-output-file' are not deleted like I'd expect. It
involves using 'execl' to call a process from within
'call-with-temporary-output-file', where the temporary file is not
deleted, at least until after it the new process terminates. Though
confusing, this is probably the right behavior.
--
Kierin Bell
bug closed, send any further explanations to
75588 <at> debbugs.gnu.org and Kierin Bell <fernseed <at> fernseed.me>
Request was from
Kierin Bell <fernseed <at> fernseed.me>
to
control <at> debbugs.gnu.org
.
(Wed, 15 Jan 2025 20:10:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
guix-patches <at> gnu.org
:
bug#75588
; Package
guix-patches
.
(Thu, 16 Jan 2025 08:53:03 GMT)
Full text and
rfc822 format available.
Message #13 received at 75588 <at> debbugs.gnu.org (full text, mbox):
Hello,
Kierin Bell <fernseed <at> fernseed.me> skribis:
> This patch fixes a bug that causes: 1) the procedure passed to
> 'call-with-temporary-output-file' to always be called with the file name
> template string "/guix-file.XXXXXX" rather than the name of the created
> temporary file; and 2) the temporary file to persist rather than being
> deleted.
>
> Unless I'm missing something, Guix is creating temporary files without
> deleting them and nobody is noticing.
[…]
> --- a/guix/build/utils.scm
> +++ b/guix/build/utils.scm
> @@ -287,15 +287,16 @@ (define (call-with-temporary-output-file proc)
> call."
> (let* ((directory (or (getenv "TMPDIR") "/tmp"))
> (template (string-append directory "/guix-file.XXXXXX"))
> - (out (mkstemp! template)))
> + (out (mkstemp! template))
> + (filename (port-filename out)))
> (dynamic-wind
> (lambda ()
> #t)
> (lambda ()
> - (proc template out))
> + (proc filename out))
> (lambda ()
> (false-if-exception (close out))
> - (false-if-exception (delete-file template))))))
> + (false-if-exception (delete-file filename))))))
AFAICS the current code is fine because ‘template’ is modified by
‘mkstemp!’:
--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> (define template (string-copy "/tmp/guix-example-XXXXXX"))
scheme@(guile-user)> (mkstemp! template)
$15 = #<input-output: /tmp/guix-example-uZ5z4s 13>
scheme@(guile-user)> template
$16 = "/tmp/guix-example-uZ5z4s"
--8<---------------cut here---------------end--------------->8---
All good?
Thanks,
Ludo’.
Information forwarded
to
guix-patches <at> gnu.org
:
bug#75588
; Package
guix-patches
.
(Thu, 16 Jan 2025 15:03:02 GMT)
Full text and
rfc822 format available.
Message #16 received at 75588 <at> debbugs.gnu.org (full text, mbox):
Hi,
Ludovic Courtès <ludo <at> gnu.org> writes:
> AFAICS the current code is fine because ‘template’ is modified by
> ‘mkstemp!’:
Yes, the code is fine --- this was a misunderstanding on my part.
I was doing something unusual that was causing temporary files to
persist, and blamed it on 'call-with-temporary-output-file':
--8<---------------cut here---------------start------------->8---
(call-with-temporary-output-file (lambda (fn port) ... (execlp "swaymsg"
"swaymsg" "exec" "--" "touch" "foo")))
--8<---------------cut here---------------end--------------->8---
Sorry for the noise!
Thanks.
--
Kierin Bell
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Fri, 14 Feb 2025 12:24:21 GMT)
Full text and
rfc822 format available.
This bug report was last modified 27 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.