From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id F27A61F5A3 for ; Fri, 15 Nov 2019 09:51:00 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 02/29] edit: use OO API of File::Temp to shorten lifetime Date: Fri, 15 Nov 2019 09:50:33 +0000 Message-Id: <20191115095100.25633-3-e@80x24.org> In-Reply-To: <20191115095100.25633-1-e@80x24.org> References: <20191115095100.25633-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Instead of relying on END{} blocks, rely on ->DESTROY so the temporary files go out-of-scope and system resources get released, sooner. --- script/public-inbox-edit | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/script/public-inbox-edit b/script/public-inbox-edit index c9884053..0accd7c1 100755 --- a/script/public-inbox-edit +++ b/script/public-inbox-edit @@ -8,7 +8,7 @@ use strict; use warnings; use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev); use PublicInbox::AdminEdit; -use File::Temp qw(tempfile); +use File::Temp (); use PublicInbox::ContentId qw(content_id); use PublicInbox::MID qw(mid_clean mids); PublicInbox::Admin::check_require('-index'); @@ -120,10 +120,16 @@ $mids $found = { $cid => $to_edit }; } -my $tmpl = 'public-inbox-edit-XXXXXX'; +my %tmpopt = ( + TEMPLATE => 'public-inbox-edit-XXXXXX', + TMPDIR => 1, + SUFFIX => $opt->{raw} ? '.eml' : '.mbox', +); + foreach my $to_edit (values %$found) { - my ($edit_fh, $edit_fn) = tempfile($tmpl, TMPDIR => 1, UNLINK => 1); + my $edit_fh = File::Temp->new(%tmpopt); $edit_fh->autoflush(1); + my $edit_fn = $edit_fh->filename; my ($ibx, $smsg) = @{$to_edit->[0]}; my $old_raw = $ibx->msg_by_smsg($smsg); delete @$ibx{qw(over mm git search)}; # cleanup