unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 5/6] xapcmd: use autodie for numerous syscalls
Date: Sat, 16 Nov 2024 07:09:52 +0000	[thread overview]
Message-ID: <20241116070953.2945078-6-e@80x24.org> (raw)
In-Reply-To: <20241116070953.2945078-1-e@80x24.org>

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 | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/lib/PublicInbox/Xapcmd.pm b/lib/PublicInbox/Xapcmd.pm
index 9a148ae4..4af50ea8 100644
--- a/lib/PublicInbox/Xapcmd.pm
+++ b/lib/PublicInbox/Xapcmd.pm
@@ -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/) {

  parent reply	other threads:[~2024-11-16  7:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-16  7:09 [PATCH 0/6] v5.12 + autodie cleanups Eric Wong
2024-11-16  7:09 ` [PATCH 1/6] index: use v5.12, remove outdated comment Eric Wong
2024-11-16  7:09 ` [PATCH 2/6] over: use autodie for open Eric Wong
2024-11-16  7:09 ` [PATCH 3/6] lei_blob: use autodie for open + seek Eric Wong
2024-11-16  7:09 ` [PATCH 4/6] admin: autodie chdir + open Eric Wong
2024-11-16  7:09 ` Eric Wong [this message]
2024-11-16  7:09 ` [PATCH 6/6] spamc: autodie for open + sysseek Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241116070953.2945078-6-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).