From 10fad7e1cf3eb0a4874afa1cb5ddb3d75afeec7d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 15 Nov 2019 09:50:33 +0000 Subject: edit: use OO API of File::Temp to shorten lifetime 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(-) (limited to 'script') 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 -- cgit v1.2.3-24-ge0c7