Message ID | 87wmewdnq1.fsf@fernseed.me |
---|---|
State | New |
Headers |
Return-Path: <guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org> X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id CA81C27BBE2; Wed, 15 Jan 2025 16:53:43 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 4F33827BBE9 for <patchwork@mira.cbaines.net>; Wed, 15 Jan 2025 16:53:39 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from <guix-patches-bounces@gnu.org>) id 1tY6dr-00013t-JK; Wed, 15 Jan 2025 11:53:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1tY6dh-00013E-UP for guix-patches@gnu.org; Wed, 15 Jan 2025 11:53:11 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1tY6db-0003hm-Fc; Wed, 15 Jan 2025 11:53:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:From:To:Subject; bh=S5ajfDQzw57w2uxUNHpf9S+KY6mlCUcg4OGnklp2h8g=; b=Moo9OD9b5xkzssGZlbd/E+y+3Dud/TDwFfXh2RgfsGMXRIIjn/X9fQh7SN01kVfcYe4OrUDM+ULxQFQVyesJlcgNRopHpljp4o75BdLo0Ix9RJ+xYdhyW5/cytp8pWm8P9nnVyh7tggiBIqfOD3Q9a9STRUgFKsHVMC4zxKrzyDNcVWUt9Q79ifAmkzB/xRPPOz5cRcUVY6NMeRd/K3wWUfaFra/kewApmfZzhtd4SCUIX4fkrGPMxPlaqAIDZQLsi/dO2x7pAEXocYC42811UKtAW2Z8ZA741GxR8dfVYCDPNnxts99mB4X02JpklMCjXoCTDmKFermLeXGCzD4Qw==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1tY6da-0001x7-Ep; Wed, 15 Jan 2025 11:53:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#75588] [PATCH] guix: utils: Delete temporary output files. Resent-From: Kierin Bell <fernseed@fernseed.me> Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org> Resent-CC: andreas@enge.fr, janneke@gnu.org, ludo@gnu.org, guix-patches@gnu.org Resent-Date: Wed, 15 Jan 2025 16:53:02 +0000 Resent-Message-ID: <handler.75588.B.17369599417436@debbugs.gnu.org> Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 75588 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 75588@debbugs.gnu.org Cc: Andreas Enge <andreas@enge.fr>, Janneke Nieuwenhuizen <janneke@gnu.org>, Ludovic =?utf-8?q?Court=C3=A8s?= <ludo@gnu.org> X-Debbugs-Original-To: guix-patches@gnu.org X-Debbugs-Original-Xcc: Andreas Enge <andreas@enge.fr>, Janneke Nieuwenhuizen <janneke@gnu.org>, Ludovic =?utf-8?q?Court=C3=A8s?= <ludo@gnu.org> Received: via spool by submit@debbugs.gnu.org id=B.17369599417436 (code B ref -1); Wed, 15 Jan 2025 16:53:02 +0000 Received: (at submit) by debbugs.gnu.org; 15 Jan 2025 16:52:21 +0000 Received: from localhost ([127.0.0.1]:58524 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces@debbugs.gnu.org>) id 1tY6cu-0001vr-PI for submit@debbugs.gnu.org; Wed, 15 Jan 2025 11:52:21 -0500 Received: from lists.gnu.org ([2001:470:142::17]:42062) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <fernseed@fernseed.me>) id 1tY6cs-0001vc-Ch for submit@debbugs.gnu.org; Wed, 15 Jan 2025 11:52:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <fernseed@fernseed.me>) id 1tY6cl-000103-VR for guix-patches@gnu.org; Wed, 15 Jan 2025 11:52:12 -0500 Received: from mout-p-102.mailbox.org ([80.241.56.152]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from <fernseed@fernseed.me>) id 1tY6ci-0003e5-QA for guix-patches@gnu.org; Wed, 15 Jan 2025 11:52:11 -0500 Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4YYBqN5zMCz9vBZ; Wed, 15 Jan 2025 17:52:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fernseed.me; s=MBO0001; t=1736959920; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=S5ajfDQzw57w2uxUNHpf9S+KY6mlCUcg4OGnklp2h8g=; b=O33knj8sfGyrdY6TAQ1aeOSh3aNz8IvORk9VaRcq7I3fSEA9H+oCVkIOjR/R8zIqXWguGT sa3nZXctJ34lqMAux2mG6UCkIZTN1RCNlUE8Nb5bSLkzfT/od7PutB8O35/d0jynQu2IkG Ku81NnGXhVKv72NYSS6oDdnOaxwn5Zfm95H9L186prCOHxAFJ0xCMc3dv3Us+lQRFArVZ4 eAbRFjllHGtzgmD+UKCvPDF2v8IDfU5SGHFbAu6hDr4ROXyOQ/6Y3CmSX7p5xpWYQGXBiB AFsCnjlwNs5dxWCR6G2ygBfqscV8qxEt2GEPaL7/QLGVdGrTAG1dqqLJkHtK4w== From: Kierin Bell <fernseed@fernseed.me> Date: Wed, 15 Jan 2025 11:51:50 -0500 Message-ID: <87wmewdnq1.fsf@fernseed.me> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=80.241.56.152; envelope-from=fernseed@fernseed.me; helo=mout-p-102.mailbox.org X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: <guix-patches.gnu.org> List-Unsubscribe: <https://lists.gnu.org/mailman/options/guix-patches>, <mailto:guix-patches-request@gnu.org?subject=unsubscribe> List-Archive: <https://lists.gnu.org/archive/html/guix-patches> List-Post: <mailto:guix-patches@gnu.org> List-Help: <mailto:guix-patches-request@gnu.org?subject=help> List-Subscribe: <https://lists.gnu.org/mailman/listinfo/guix-patches>, <mailto:guix-patches-request@gnu.org?subject=subscribe> Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches |
Series |
[bug#75588] guix: utils: Delete temporary output files.
|
|
Commit Message
Kierin Bell
Jan. 15, 2025, 4:51 p.m. UTC
* 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(-) base-commit: b696658ee8e0655b17f5d26e024956b5148e36d6
Comments
help-debbugs@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.
Hello, Kierin Bell <fernseed@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’.
Hi, Ludovic Courtès <ludo@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.
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