]> Sergey Matveev's repositories - public-inbox.git/commitdiff
edit: use OO API of File::Temp to shorten lifetime
authorEric Wong <e@80x24.org>
Fri, 15 Nov 2019 09:50:33 +0000 (09:50 +0000)
committerEric Wong <e@80x24.org>
Sat, 16 Nov 2019 11:05:23 +0000 (11:05 +0000)
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

index c98840531fd674c1716aeb0a1aed0b77746d725f..0accd7c19e28a9126126c6ae203f762343bab319 100755 (executable)
@@ -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