]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
use autodie in more places (extindex, pop3d, ipc)
authorEric Wong <e@80x24.org>
Tue, 19 Aug 2025 00:33:32 +0000 (00:33 +0000)
committerEric Wong <e@80x24.org>
Wed, 20 Aug 2025 19:10:12 +0000 (19:10 +0000)
Another gradual step towards autodie-ification of our codebase.

lib/PublicInbox/ExtSearchIdx.pm
lib/PublicInbox/IPC.pm
lib/PublicInbox/POP3D.pm
t/ipc.t

index 1fd86e059af8ecc7a8d27e6a7b30844ef9e053ce..875928689f4573a2162c294dae92378947ead51d 100644 (file)
@@ -21,6 +21,7 @@ package PublicInbox::ExtSearchIdx;
 use strict;
 use v5.10.1;
 use parent qw(PublicInbox::ExtSearch PublicInbox::Umask PublicInbox::Lock);
+use autodie qw(mkdir);
 use Carp qw(croak carp);
 use Scalar::Util qw(blessed);
 use Sys::Hostname qw(hostname);
@@ -1278,7 +1279,7 @@ sub idx_init { # similar to V2Writable
                        }
                }
        } elsif ($!{ENOENT}) {
-               mkdir($pd) or die "mkdir($pd): $!";
+               mkdir $pd;
        } else {
                die "opendir($pd): $!";
        }
index 806653dca2a3929905c6423d3fedc4ec6e84c5d9..1395c4625098a616a5dd7c3555874dc40c3f75ff 100644 (file)
@@ -10,7 +10,7 @@
 package PublicInbox::IPC;
 use v5.12;
 use parent qw(Exporter);
-use autodie qw(close pipe read socketpair);
+use autodie qw(close pipe read send socketpair);
 use Errno qw(EAGAIN EINTR);
 use Carp qw(croak);
 use PublicInbox::DS qw(awaitpid);
@@ -265,7 +265,7 @@ sub wq_broadcast {
        my $buf = ipc_freeze([$sub, @args]);
        for my $bcast1 (values %$wkr) {
                my $sock = $bcast1 // $self->{-wq_s1} // next;
-               send($sock, $buf, 0) // croak "send: $!";
+               send($sock, $buf, 0);
                # XXX shouldn't have to deal with EMSGSIZE here...
        }
 }
index a30fc6770e650596431d66616343b5ebd6306d28..8eefba80d1842de76ec2334d185edec21fad6087 100644 (file)
@@ -5,6 +5,7 @@
 package PublicInbox::POP3D;
 use v5.12;
 use parent qw(PublicInbox::Lock);
+use autodie qw(open);
 use DBI qw(:sql_types); # SQL_BLOB
 use Carp ();
 use File::Temp 0.19 (); # 0.19 for ->newdir
@@ -140,7 +141,7 @@ sub state_dbh_new {
 
        # ensure the interprocess fcntl lock file exists
        $f = "$self->{pi_cfg}->{'publicinbox.pop3state'}/txn.locks";
-       open my $fh, '+>>', $f or Carp::croak("open($f): $!");
+       open my $fh, '+>>', $f;
        $self->{txn_fh} = $fh;
 
        create_state_tables($self, $dbh);
diff --git a/t/ipc.t b/t/ipc.t
index fc6f96a2330af43f46c578aca12a0bdefc74f051..47c3610353fa47d3f4bdca0eb649dbdebd54909c 100644 (file)
--- a/t/ipc.t
+++ b/t/ipc.t
@@ -2,8 +2,9 @@
 # Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use v5.12;
-use autodie qw(seek);
+use autodie qw(fork open pipe seek);
 use PublicInbox::TestCommon;
+use PublicInbox::IO qw(try_cat);
 use Fcntl qw(SEEK_SET);
 use PublicInbox::SHA qw(sha1_hex);
 require_mods(qw(Storable||Sereal));
@@ -11,7 +12,8 @@ require_ok 'PublicInbox::IPC';
 my ($tmpdir, $for_destroy) = tmpdir();
 state $once = eval <<'';
 package PublicInbox::IPC;
-use strict;
+use v5.12;
+use autodie qw(open);
 use PublicInbox::SHA qw(sha1_hex);
 sub test_array { qw(test array) }
 sub test_scalar { 'scalar' }
@@ -33,7 +35,7 @@ sub test_sha {
 }
 sub test_append_pid {
        my ($self, $file) = @_;
-       open my $fh, '>>', $file or die "open: $!";
+       open my $fh, '>>', $file;
        $fh->autoflush(1);
        print $fh "$$\n" or die "print: $!";
 }
@@ -96,16 +98,14 @@ $test->('local');
 $ipc->ipc_worker_stop; # idempotent
 
 # work queues
-pipe(my ($ra, $wa)) or BAIL_OUT $!;
-pipe(my ($rb, $wb)) or BAIL_OUT $!;
-pipe(my ($rc, $wc)) or BAIL_OUT $!;
-open my $warn, '+>', undef or BAIL_OUT;
+pipe(my $ra, my $wa);
+pipe(my $rb, my $wb);
+pipe(my $rc, my $wc);
+open my $warn, '+>', undef;
 $warn->autoflush(0);
 local $SIG{__WARN__} = sub { print $warn "PID:$$ ", @_ };
 my @ppids;
-open my $agpl, '<', 'COPYING' or BAIL_OUT "AGPL-3 missing: $!";
-my $big = do { local $/; <$agpl> } // BAIL_OUT "read: $!";
-close $agpl or BAIL_OUT "close: $!";
+my $big = try_cat('COPYING') || BAIL_OUT "try_cat(COPYING): $!";
 
 for my $t ('worker', 'worker again') {
        my $ppid = $ipc->wq_workers_start('wq', 1);
@@ -147,7 +147,7 @@ SKIP: {
        skip 'Socket::MsgHdr or Inline::C missing', 3 if !$ppids[0];
        is_xdeeply(\@ppids, [$$, undef],
                'parent pid returned in wq_workers_start');
-       my $pid = fork // BAIL_OUT $!;
+       my $pid = fork;
        if ($pid == 0) {
                use POSIX qw(_exit);
                $ipc->wq_io_do('test_write_each_fd', [ $wa, $wb, $wc ], $$);
@@ -187,8 +187,7 @@ SKIP: {
        is($ipc->wq_workers_start('wq', 2), $$, 'workers started again');
        $ipc->wq_broadcast('test_append_pid', "$tmpdir/append_pid");
        $ipc->wq_close;
-       open my $fh, '<', "$tmpdir/append_pid" or BAIL_OUT "open: $!";
-       chomp(my @pids = <$fh>);
+       chomp(my @pids = try_cat("$tmpdir/append_pid"));
        my %pids = map { $_ => 1 } grep(/\A[0-9]+\z/, @pids);
        is(scalar keys %pids, 2, 'broadcast hit both PIDs');
 }