From: Eric Wong Date: Sat, 16 Nov 2024 07:09:52 +0000 (+0000) Subject: xapcmd: use autodie for numerous syscalls X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=049eaff036ffcec0b2ec7c8f1a5ce16a4fd66920;p=thirdparty%2Fpublic-inbox.git xapcmd: use autodie for numerous syscalls 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. --- diff --git a/lib/PublicInbox/Xapcmd.pm b/lib/PublicInbox/Xapcmd.pm index 9a148ae45..4af50ea81 100644 --- a/lib/PublicInbox/Xapcmd.pm +++ b/lib/PublicInbox/Xapcmd.pm @@ -2,6 +2,7 @@ # License: AGPL-3.0+ 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/) {