From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 4/6] admin: autodie chdir + open
Date: Sat, 16 Nov 2024 07:09:51 +0000 [thread overview]
Message-ID: <20241116070953.2945078-5-e@80x24.org> (raw)
In-Reply-To: <20241116070953.2945078-1-e@80x24.org>
autodie gives us more consistent error messages and reduces
visual noise on our end. We can also open() directly into a
hash entry without relying on a temporary variable.
---
lib/PublicInbox/Admin.pm | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/lib/PublicInbox/Admin.pm b/lib/PublicInbox/Admin.pm
index bb5d3653..fb745cf8 100644
--- a/lib/PublicInbox/Admin.pm
+++ b/lib/PublicInbox/Admin.pm
@@ -6,6 +6,7 @@
package PublicInbox::Admin;
use v5.12;
use parent qw(Exporter);
+use autodie qw(chdir open);
our @EXPORT_OK = qw(setup_signals fmt_localtime);
use PublicInbox::Config;
use PublicInbox::Inbox;
@@ -313,9 +314,7 @@ sub progress_prepare ($;$) {
$opt->{quiet} = !$opt->{verbose};
}
if ($opt->{quiet}) {
- open my $null, '>', '/dev/null' or
- die "failed to open /dev/null: $!\n";
- $opt->{1} = $null; # suitable for spawn() redirect
+ open $opt->{1}, '>', '/dev/null'; # suitable for spawn() redirect
} else {
$opt->{verbose} ||= 1;
$dst //= \*STDERR;
@@ -378,7 +377,7 @@ sub do_chdir ($) {
my $chdir = $_[0] // return;
for my $d (@$chdir) {
next if $d eq ''; # same as git(1)
- chdir $d or die "cd $d: $!";
+ chdir $d;
}
}
next prev 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 ` Eric Wong [this message]
2024-11-16 7:09 ` [PATCH 5/6] xapcmd: use autodie for numerous syscalls Eric Wong
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-5-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).