]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
treewide: use ->close to call ProcessIO->CLOSE
authorEric Wong <e@80x24.org>
Thu, 2 Nov 2023 09:35:30 +0000 (09:35 +0000)
committerEric Wong <e@80x24.org>
Fri, 3 Nov 2023 06:39:28 +0000 (06:39 +0000)
This will open the door for us to drop `tie' usage from
ProcessIO completely in favor of OO method dispatch.  While
OO method dispatches (e.g. `$fh->close') are slower than normal
subroutine calls, it hardly matters in this case since process
teardown is a fairly rare operation and we continue to use
`close($fh)' for Maildir writes.

18 files changed:
lib/PublicInbox/Config.pm
lib/PublicInbox/GitCredential.pm
lib/PublicInbox/Import.pm
lib/PublicInbox/LEI.pm
lib/PublicInbox/LeiInput.pm
lib/PublicInbox/LeiRediff.pm
lib/PublicInbox/LeiViewText.pm
lib/PublicInbox/LeiXSearch.pm
lib/PublicInbox/MboxReader.pm
lib/PublicInbox/SearchIdx.pm
lib/PublicInbox/Spawn.pm
lib/PublicInbox/V2Writable.pm
script/public-inbox-convert
t/httpd-corner.t
t/lei-q-kw.t
t/spawn.t
xt/git_async_cmp.t
xt/httpd-async-stream.t

index 0a5721035b3c6427ce08353af5e871e2983a68d0..01cb536d96026e3cb1c7070f0e959f4202e31d26 100644 (file)
@@ -192,7 +192,7 @@ sub git_config_dump {
        push(@cmd, '-f', $file) if !@opt_c && defined($file);
        my $fh = popen_rd(\@cmd, \%env, $opt);
        my $rv = config_fh_parse($fh, "\0", "\n");
-       close $fh or die "@cmd failed: \$?=$?\n";
+       $fh->close or die "@cmd failed: \$?=$?\n";
        $rv->{-opt_c} = \@opt_c if @opt_c; # for ->urlmatch
        $rv->{-f} = $file;
        bless $rv, $class;
index 10114a10bb347decab3871c8e43f325e3b111027..a4444e2c5847195259df677f0d26246f985831f2 100644 (file)
@@ -30,7 +30,7 @@ sub run ($$;$) {
        close $in_w or die "close (git credential $op): $!";
        return $out_r if $op eq 'fill';
        <$out_r> and die "unexpected output from `git credential $op'\n";
-       close $out_r or die "`git credential $op' failed: \$!=$! \$?=$?\n";
+       $out_r->close or die "`git credential $op' failed: \$!=$! \$?=$?\n";
 }
 
 sub check_netrc {
@@ -61,7 +61,7 @@ sub fill {
                /\A([^=]+)=(.*)\z/ or die "bad line: $_\n";
                $self->{$1} = $2;
        }
-       close $out_r or die "git credential fill failed: \$!=$! \$?=$?\n";
+       $out_r->close or die "git credential fill failed: \$!=$! \$?=$?\n";
        $self->{filled} = 1;
 }
 
index 6eee8774a2d92389b77b9fa4bd21e0f1c3ede449..e12a56e8c74cb2f09d8f51125ce8d07448897c0b 100644 (file)
@@ -476,7 +476,7 @@ sub done {
        my $io = delete $self->{io} or return;
        eval {
                print $io "done\n" or wfail;
-               close $io; # reaps and dies on error
+               $io->close or croak "close fast-import \$?=$?"; # reaps
        };
        my $wait_err = $@;
        my $nchg = delete $self->{nchg};
@@ -489,7 +489,7 @@ sub done {
        die $wait_err if $wait_err;
 }
 
-sub atfork_child { close(delete($_[0]->{io}) // return) }
+sub atfork_child { (delete($_[0]->{io}) // return)->close }
 
 sub digest2mid ($$;$) {
        my ($dig, $hdr, $fallback_time) = @_;
@@ -598,7 +598,7 @@ sub replace_oids {
                        push @buf, $_;
                }
        }
-       close $rd;
+       $rd->close or die "E: git @export (\$?=$?)";
        if (@buf) {
                print $io @buf or wfail;
        }
index 0f6f7f6fbd82ab90cc2516fc68a6a00e0c162bd6..2832db63d1dbe747dff46a4800bfda49e081bd9a 100644 (file)
@@ -501,7 +501,7 @@ sub err ($;@) {
        my @eor = (substr($_[-1]//'', -1, 1) eq "\n" ? () : ("\n"));
        print $err @_, @eor and return;
        my $old_err = delete $self->{2};
-       close($old_err) if $! == EPIPE && $old_err;
+       $old_err->close if $! == EPIPE && $old_err;
        $err = $self->{2} = ($self->{pgr} // [])->[2] // *STDERR{GLOB};
        print $err @_, @eor or print STDERR @_, @eor;
 }
@@ -516,7 +516,7 @@ sub qfin { # show message on finalization (LeiFinmsg)
 
 sub fail_handler ($;$$) {
        my ($lei, $code, $io) = @_;
-       close($io) if $io; # needed to avoid warnings on SIGPIPE
+       $io->close if $io; # needed to avoid warnings on SIGPIPE
        _drop_wq($lei);
        x_it($lei, $code // (1 << 8));
 }
@@ -565,7 +565,7 @@ sub child_error { # passes non-fatal curl exit codes to user
 
 sub note_sigpipe { # triggers sigpipe_handler
        my ($self, $fd) = @_;
-       close(delete($self->{$fd})); # explicit close silences Perl warning
+       delete($self->{$fd})->close; # explicit close silences Perl warning
        $self->{pkt_op_p}->pkt_do('sigpipe_handler') if $self->{pkt_op_p};
        x_it($self, 13);
 }
@@ -1129,7 +1129,7 @@ sub stop_pager {
        my ($self) = @_;
        my $pgr = delete($self->{pgr}) or return;
        $self->{2} = $pgr->[2];
-       close(delete($self->{1})) if $self->{1};
+       delete($self->{1})->close if $self->{1};
        $self->{1} = $pgr->[1];
 }
 
index 28b73ca9e923bb3d9b518ef8f64cdf62d15ec861..f7c3f573b0b99f098dd6c33254eefb667465057d 100644 (file)
@@ -246,7 +246,7 @@ sub input_path_url {
                        my $fh = popen_rd($fp, undef, $rdr);
                        eval { $self->input_fh('eml', $fh, $input, @args) };
                        my @err = ($@ ? $@ : ());
-                       close($fh) or push @err, "\$?=$?";
+                       $fh->close or push @err, "\$?=$?";
                        $lei->child_error($?, "@$fp failed: @err") if @err;
                } else {
                        $self->folder_missing("$ifmt:$input");
index 230f3e83e9ec9509aa5a9b13a4acb05427ef69b6..fdff4b4bd679001a59c84e3920e489d8a5d8762f 100644 (file)
@@ -126,7 +126,7 @@ EOM
                        qw(fast-import --quiet --done --date-format=raw)],
                        $lei->{env}, { 2 => $lei->{2} });
        print $w $ta, "\n", $tb, "\ndone\n" or die "print fast-import: $!";
-       close $w or die "close w fast-import: \$?=$? \$!=$!";
+       $w->close or die "close w fast-import: \$?=$? \$!=$!";
 
        my $cmd = [ 'diff' ];
        _lei_diff_prepare($lei, $cmd);
index 704418671fda013fde2dee339223b577e7f9236b..ce9f248eafe54c7db8c8119f90240013972181dd 100644 (file)
@@ -75,7 +75,7 @@ sub new {
        my @cmd = qw(git config -z --includes -l); # reuse normal git config
        my $r = popen_rd(\@cmd, undef, { 2 => $lei->{2} });
        my $cfg = PublicInbox::Config::config_fh_parse($r, "\0", "\n");
-       if (!close($r)) {
+       if ($r->close) {
                warn "# @cmd failed, no color (non-fatal \$?=$?)\n";
                return $self;
        }
index 241b9dabcd89a83f053bae581cf639d28a2373bc..5443188d79308587aef4c5d71caa4791a23d20ed 100644 (file)
@@ -353,14 +353,14 @@ print STDERR $_;
                                                $lei, $each_smsg);
                $lei->sto_done_request if delete($self->{-sto_imported});
                my $nr = delete $lei->{-nr_remote_eml} // 0;
-               close $cfh;
+               $cfh->close;
                my $code = $?;
                if (!$code) { # don't update if no results, maybe MTA is down
                        $lei->{lss}->cfg_set($key, $start) if $key && $nr;
                        mset_progress($lei, $lei->{-current_url}, $nr, $nr);
                        next;
                }
-               close(delete($rdr->{2})) if @lbf_tee;
+               delete($rdr->{2})->close if @lbf_tee;
                seek($cerr, 0, SEEK_SET);
                read($cerr, my $err, -s $cerr);
                truncate($cerr, 0);
@@ -396,8 +396,8 @@ sub query_done { # EOF callback for main daemon
        $lei->{ovv}->ovv_end($lei);
        if ($l2m) { # close() calls LeiToMail reap_compress
                if (my $out = delete $lei->{old_1}) {
-                       if (my $mbout = $lei->{1}) {
-                               close($mbout) or die <<"";
+                       if (my $mbout = $lei->{1}) { # compressor pipe process
+                               $mbout->close or die <<"";
 Error closing $lei->{ovv}->{dst}: \$!=$! \$?=$?
 
                        }
index d67fb4ebed06a342d6dda39e3b24e769fc4d4b10..3d78ca23118a248e7df6425d0303bb693572fcdd 100644 (file)
@@ -29,7 +29,7 @@ sub _mbox_from {
        my @raw;
        while (defined(my $r = read($mbfh, $buf, 65536, length($buf)))) {
                if ($r == 0) { # close here to check for "curl --fail"
-                       close($mbfh) or die "error closing mbox: \$?=$? $!";
+                       $mbfh->close or die "error closing mbox: \$?=$? $!";
                        @raw = ($buf);
                } else {
                        @raw = split(/$from_strict/mos, $buf, -1);
@@ -88,7 +88,7 @@ sub _mbox_cl ($$$;@) {
        my $buf = '';
        while (defined(my $r = read($mbfh, $buf, 65536, length($buf)))) {
                if ($r == 0) { # detect "curl --fail"
-                       close($mbfh) or
+                       $mbfh->close or
                                die "error closing mboxcl/mboxcl2: \$?=$? $!";
                        undef $mbfh;
                }
index 3c64c715ad7d0e72b22412fa5552d1d2ad3babef..78519b22bf8346fbaf69b4f32b7fd981829091b8 100644 (file)
@@ -980,7 +980,7 @@ sub log2stack ($$$) {
                        $stk->push_rec('m', $at, $ct, $oid, $cmt);
                }
        }
-       close $fh or die "git log failed: \$?=$?";
+       $fh->close or die "git log failed: \$?=$?";
        $stk //= PublicInbox::IdxStack->new;
        $stk->read_prepare;
 }
index e7d2c6ea817203e9c8df5253c1067468e2dba752..b4f37bea97169828dc71e5aa5eefd8c0cd31fcd2 100644 (file)
@@ -421,7 +421,7 @@ sub run_qx {
                local $/;
                $ret[0] = <$fh>;
        }
-       close $fh; # caller should check $?
+       $fh->close; # caller should check $?
        read_out_err($opt);
        wantarray ? @ret : $ret[0];
 }
index 191c55889e126e70a1a1c70fd1dee662c9571ad1..4d606dfefe25bc89c1a7feac76c6ae761c84c957 100644 (file)
@@ -1070,7 +1070,7 @@ sub unindex_todo ($$$) {
                /\A:\d{6} 100644 $OID ($OID) [AM]\tm$/o or next;
                $self->git->cat_async($1, $unindex_oid, { %$sync, oid => $1 });
        }
-       close $fh or die "git log failed: \$?=$?";
+       $fh->close or die "git log failed: \$?=$?";
        $self->git->async_wait_all;
 
        return unless $sync->{-opt}->{prune};
index 96f6d2ea018f4e11d21b7cbb45dd09ce076288ac..d8186809d165688fee563591ce8be1ed05ba3db2 100755 (executable)
@@ -1,5 +1,5 @@
 #!/usr/bin/perl -w
-# Copyright (C) 2018-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <http://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
 use v5.10.1;
@@ -158,7 +158,7 @@ while (<$rd>) {
        last if $_ eq "done\n";
        print $io $_ or $im->wfail;
 }
-close $rd or die "fast-export: \$?=$? \$!=$!\n";
+$rd->close or die "fast-export: \$?=$? \$!=$!\n";
 $io = undef;
 $v2w->done;
 if (my $old_mm = $old->mm) {
index 2d2d10612bcffb41c5387124d42a2cb3fb52f01e..da1c24b951c0dde7e6f1fb425095135d1ef4a349 100644 (file)
@@ -368,7 +368,7 @@ SKIP: {
                $n += $r;
                $buf =~ /\A\0+\z/ or $non_zero++;
        }
-       close $fh or die "close curl pipe: $!";
+       $fh->close or die "close curl pipe: $!";
        is($?, 0, 'curl succesful');
        is($n, 30 * 1024 * 1024, 'got expected output from curl');
        is($non_zero, 0, 'read all zeros');
index 4edee72a54b733a6237261a98b6c86b352939843..06e1df6cab572533784553c12ff649e29a1de150 100644 (file)
@@ -1,5 +1,5 @@
 #!perl -w
-# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict; use v5.10.1; use PublicInbox::TestCommon;
 use POSIX qw(mkfifo);
@@ -51,7 +51,7 @@ SKIP: {
                '--import-before fails on non-seekable output');
        like($lei_err, qr/not seekable/, 'unseekable noted in error');
        is(do { local $/; <$cat> }, '', 'no output on FIFO');
-       close $cat;
+       $cat->close;
        $cat = popen_rd(['cat', $o]);
        lei_ok(qw(q m:qp@example.com -o), "mboxrd:$o");
        my $buf = do { local $/; <$cat> };
index 4b3baae4e2e5d8b0865dbd1741bd1f8b89f7973f..938a2e5e6aaae215ba70bc8c4371558f609b64b8 100644 (file)
--- a/t/spawn.t
+++ b/t/spawn.t
@@ -80,7 +80,7 @@ EOF
        is($rdy, 'RDY', 'got ready signal, waitpid(-1) works in child');
        ok(kill('CHLD', $pid), 'sent SIGCHLD to child');
        is(readline($rd), "HI\n", '$SIG{CHLD} works in child');
-       ok(close $rd, 'popen_rd close works');
+       ok($rd->close, 'popen_rd close works');
        PublicInbox::DS::sig_setmask($oldset);
 }
 
@@ -133,13 +133,13 @@ EOF
        is($buf, "hello\n", 'tied gets works');
        is(sysread($fh, $buf, 6), 0, 'sysread got EOF');
        $? = 1;
-       ok(close($fh), 'close succeeds');
+       ok($fh->close, 'close succeeds');
        is($?, 0, '$? set properly');
 }
 
 {
        my $fh = popen_rd([qw(false)]);
-       ok(!close($fh), 'close fails on false');
+       ok(!$fh->close, 'close fails on false');
        isnt($?, 0, '$? set properly: '.$?);
 }
 
@@ -152,7 +152,7 @@ EOF
 { # ->CLOSE vs ->DESTROY waitpid caller distinction
        my @c;
        my $fh = popen_rd(['true'], undef, undef, sub { @c = caller });
-       ok(close($fh), '->CLOSE fired and successful');
+       ok($fh->close, '->CLOSE fired and successful');
        ok(scalar(@c), 'callback fired by ->CLOSE');
        ok(grep(!m[/PublicInbox/DS\.pm\z], @c), 'callback not invoked by DS');
 
@@ -183,7 +183,7 @@ EOF
        my @w;
        local $SIG{__WARN__} = sub { push @w, @_ };
        close $w;
-       close $fh;
+       $fh->close; # may set $?
        is($?, 0, 'cat exited');
        is(scalar(@arg), 2, 'callback got args');
        is($arg[1], 'hi', 'passed arg');
index 9edc1f3752d590dc48c52956f4649105f91ee0df..4038898b3175ebf720be1956ef9a4102bbddff73 100644 (file)
@@ -31,7 +31,7 @@ my $async = timeit($nr, sub {
                my ($oid, undef, undef) = split(/ /);
                $git->cat_async($oid, $cb);
        }
-       close $cat or die "cat: $?";
+       $cat->close or xbail "cat: $?";
        $git->async_wait_all;
        push @dig, ['async', $dig->hexdigest ];
 });
@@ -44,7 +44,7 @@ my $sync = timeit($nr, sub {
                my $bref = $git->cat_file($oid);
                $dig->add($$bref);
        }
-       close $cat or die "cat: $?";
+       $cat->close or xbail "cat: $?";
        push @dig, ['sync', $dig->hexdigest ];
 });
 
index 904f2ae99aa3f46a6ace45edf2c591a8454ac6cf..099ceb790c5120aa5659bb54a143d0da7f21e4ac 100644 (file)
@@ -67,7 +67,7 @@ my $do_get_all = sub {
        }
        my $res = $dig->hexdigest;
        my $elapsed = sprintf('%0.3f', now() - $t0);
-       close $rd or die "close curl failed: $! \$?=$?\n";
+       $rd->close or xbail "close curl failed: $! \$?=$?\n";
        print STDERR "# $job $$ ($?) $res (${elapsed}s) $bytes bytes\n";
        $res;
 };