]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
xapcmd: use autodie for numerous syscalls
authorEric Wong <e@80x24.org>
Sat, 16 Nov 2024 07:09:52 +0000 (07:09 +0000)
committerEric Wong <e@80x24.org>
Sun, 17 Nov 2024 18:54:12 +0000 (18:54 +0000)
autodie allows us to simplify a multi-line statement for
conditional rename() and improve error message consistency
with the rest of our codebase.

syswrite() error checking was missing before and now exists
trivially due to autodie.

lib/PublicInbox/Xapcmd.pm

index 9a148ae45dabdf58349b792431fcbc3fe0aa1d81..4af50ea81ba2e72cef642388cd8f159e6e2c0128 100644 (file)
@@ -2,6 +2,7 @@
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 package PublicInbox::Xapcmd;
 use v5.12;
+use autodie qw(chmod opendir rename syswrite);
 use PublicInbox::Spawn qw(which popen_rd);
 use PublicInbox::Syscall;
 use PublicInbox::Admin qw(setup_signals);
@@ -61,12 +62,9 @@ sub commit_changes ($$$$) {
                        next;
                }
 
-               chmod($mode & 07777, $new) or die "chmod($new): $!\n";
-               if ($have_old) {
-                       rename($old, "$new/old") or
-                                       die "rename $old => $new/old: $!\n";
-               }
-               rename($new, $old) or die "rename $new => $old: $!\n";
+               chmod $mode & 07777, $new;
+               rename $old, "$new/old" if $have_old;
+               rename $new, $old;
                push @old_shard, "$old/old" if $have_old;
        }
 
@@ -219,7 +217,7 @@ sub prepare_run {
                PublicInbox::Syscall::nodatacow_dir($wip->dirname);
                push @queue, [ $old, $wip ];
        } elsif (defined $old) {
-               opendir my $dh, $old or die "Failed to opendir $old: $!\n";
+               opendir my $dh, $old;
                my @old_shards;
                while (defined(my $dn = readdir($dh))) {
                        if ($dn =~ /\A[0-9]+\z/) {