]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
edit: use autodie and favor flush over autoflush
authorEric Wong <e@80x24.org>
Sat, 15 Feb 2025 11:10:05 +0000 (11:10 +0000)
committerEric Wong <e@80x24.org>
Mon, 17 Feb 2025 20:09:06 +0000 (20:09 +0000)
Using a single ->flush reduces iops for the (default) non-raw
case and autodie for `open' makes error messages more
consistent.

script/public-inbox-edit

index c76579e4bfa8a14dd8e4a87687677fe9e0343193..a363f0c884072fa4b755b0ea47f81d8c2a70c848 100755 (executable)
@@ -5,7 +5,8 @@
 # Used for editing messages in a public-inbox.
 # Supports v2 inboxes only, for now.
 use strict;
-use warnings;
+use v5.10.1; # TODO: check unicode_strings compat
+use autodie qw(open);
 use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev);
 use PublicInbox::AdminEdit;
 use File::Temp 0.19 (); # 0.19 for TMPDIR
@@ -142,7 +143,6 @@ my %tmpopt = (
 
 foreach my $to_edit (values %$found) {
        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);
@@ -151,12 +151,11 @@ foreach my $to_edit (values %$found) {
        my $tmp = $$old_raw;
        if (!$opt->{raw}) {
                my $oid = $smsg->{blob};
-               print $edit_fh "From mboxrd\@$oid Thu Jan  1 00:00:00 1970\n"
-                       or die "failed to write From_ line: $!";
+               print $edit_fh "From mboxrd\@$oid Thu Jan  1 00:00:00 1970\n";
                $tmp =~ s/^(>*From )/>$1/gm;
        }
-       print $edit_fh $tmp or
-               die "failed to write tempfile for editing: $!";
+       print $edit_fh $tmp;
+       $edit_fh->flush or die "E: flush($edit_fn): $!";
 
        # run the editor, respecting spaces/quote
 retry_edit:
@@ -183,8 +182,7 @@ retry_edit:
 
        # reread the edited file, not using $edit_fh since $EDITOR may
        # rename/relink $edit_fn
-       open my $new_fh, '<', $edit_fn or
-               die "can't read edited file ($edit_fn): $!\n";
+       open my $new_fh, '<', $edit_fn;
        my $new_raw = PublicInbox::IO::read_all $new_fh;
 
        if (!$opt->{raw}) {