* [PATCH 23/30] init: use autodie to reduce distractions
2023-10-17 23:37 7% [PATCH 00/30] autodie-ification and code simplifications Eric Wong
@ 2023-10-17 23:38 6% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2023-10-17 23:38 UTC (permalink / raw)
To: meta
This hurts startup time a bit, but our tests use run_script
by default and I don't think normal users call -init enough
to care.
---
script/public-inbox-init | 27 +++++++++++----------------
1 file changed, 11 insertions(+), 16 deletions(-)
diff --git a/script/public-inbox-init b/script/public-inbox-init
index b3e94faf..6420db7e 100755
--- a/script/public-inbox-init
+++ b/script/public-inbox-init
@@ -4,6 +4,7 @@
use strict;
use v5.10.1;
use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/;
+use autodie qw(open chmod close rename);
use Fcntl qw(:DEFAULT);
my $help = <<EOF; # the following should fit w/o scrolling in 80x24 term:
usage: public-inbox-init NAME INBOX_DIR HTTP_URL ADDRESS [ADDRESS..]
@@ -126,15 +127,12 @@ my $perm = 0644 & ~umask;
my %seen;
if (-e $pi_config) {
require PublicInbox::Git;
- open(my $oh, '<', $pi_config) or die "unable to read $pi_config: $!\n";
- my @st = stat($oh);
+ open(my $oh, '<', $pi_config);
+ my @st = stat($oh) or die "(f)stat failed on $pi_config: $!\n";
$perm = $st[2];
- defined $perm or die "(f)stat failed on $pi_config: $!\n";
- chmod($perm & 07777, $fh) or
- die "(f)chmod failed on future $pi_config: $!\n";
- my $old = PublicInbox::Git::read_all($oh);
- print $fh $old or die "failed to write: $!\n";
- close $oh or die "failed to close $pi_config: $!\n";
+ chmod($perm & 07777, $fh);
+ print $fh PublicInbox::Git::read_all($oh);
+ close $oh;
# yes, this conflict checking is racy if multiple instances of this
# script are run by the same $PI_DIR
@@ -161,7 +159,7 @@ if (-e $pi_config) {
$indexlevel //= $ibx->{indexlevel} if $ibx;
}
my $pi_config_tmp = $fh->filename;
-close($fh) or die "failed to close $pi_config_tmp: $!\n";
+close($fh);
my $pfx = "publicinbox.$name";
my @x = (qw/git config/, "--file=$pi_config_tmp");
@@ -216,8 +214,8 @@ $ibx->init_inbox(0, $skip_epoch, $skip_artnum);
my $f = "$inboxdir/description";
if (sysopen $fh, $f, O_CREAT|O_EXCL|O_WRONLY) {
- print $fh "public inbox for $address[0]\n" or die "print($f): $!";
- close $fh or die "close($f): $!";
+ print $fh "public inbox for $address[0]\n";
+ close $fh;
}
# needed for git prior to v2.1.0
@@ -248,9 +246,6 @@ for my $kv (@c_extra) {
}
# needed for git prior to v2.1.0
-chmod($perm & 07777, $pi_config_tmp) or
- die "(f)chmod failed on future $pi_config: $!\n";
-
-rename $pi_config_tmp, $pi_config or
- die "failed to rename `$pi_config_tmp' to `$pi_config': $!\n";
+chmod($perm & 07777, $pi_config_tmp);
+rename $pi_config_tmp, $pi_config;
undef $auto_unlink; # trigger ->DESTROY
^ permalink raw reply related [relevance 6%]
* [PATCH 00/30] autodie-ification and code simplifications
@ 2023-10-17 23:37 7% Eric Wong
2023-10-17 23:38 6% ` [PATCH 23/30] init: use autodie to reduce distractions Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2023-10-17 23:37 UTC (permalink / raw)
To: meta
Noisy code is less pleasant to work on, so use autodie more and
a few more simplifications. There's a couple of small bugfixes
discovered along the way, too.
Eric Wong (30):
lei_mirror: start converting to autodie
lei_mirror: autodie most `close' calls
lei_mirror: use autodie for most `open' calls
git: introduce read_all function
import: use read_all to detect short reads
lei_mirror: use read_all
use read_all in more places to improve safety
xap_helper*: use autodie in more places
xap_helper: die more easily in both implementations
xap_helper: simplify SIGTERM exit checks
xap_helper: autodie for getsockopt
xap_client: autodie for pipe and socketpair
xt/git-http-backend: remove Net::HTTP usage
ds: introduce and use do_fork helper
ds: get rid of SetLoopTimeout
cindex: drop some unused functions
syscall: common $F_SETPIPE_SZ definition
t/lei-up: additional diagnostics for match failures
test_common: use autodie and read_all where possible
test_common: only hide TCP port in messages
test_common: use $cwdfh for every run_script command
init: drop extraneous `+'
init: use autodie to reduce distractions
xt/mem-imapd-tls: remove unused/broken epoll imports
xt/mem-imapd-tls: reduce FDs for lsof use
lei: use autodie where appropriate
lei_auth: update comments and use v5.12
lei_config: drop redundant open check
convert: use read_all to simplify error checks
idx_stack: use autodie + read_all
lib/PublicInbox/CidxLogP.pm | 4 +-
lib/PublicInbox/CodeSearchIdx.pm | 5 --
lib/PublicInbox/DS.pm | 36 ++++----
lib/PublicInbox/Daemon.pm | 16 ++--
lib/PublicInbox/EOFpipe.pm | 6 +-
lib/PublicInbox/Gcf2.pm | 7 +-
lib/PublicInbox/Git.pm | 19 +++--
lib/PublicInbox/IPC.pm | 12 +--
lib/PublicInbox/IdxStack.pm | 20 ++---
lib/PublicInbox/Import.pm | 8 +-
lib/PublicInbox/InboxWritable.pm | 6 +-
lib/PublicInbox/LEI.pm | 48 +++++------
lib/PublicInbox/LeiALE.pm | 11 +--
lib/PublicInbox/LeiAuth.pm | 7 +-
lib/PublicInbox/LeiBlob.pm | 6 +-
lib/PublicInbox/LeiConfig.pm | 4 +-
lib/PublicInbox/LeiMailSync.pm | 5 +-
lib/PublicInbox/LeiMirror.pm | 131 ++++++++++++++----------------
lib/PublicInbox/LeiSucks.pm | 5 +-
lib/PublicInbox/LeiXSearch.pm | 2 +-
lib/PublicInbox/MultiGit.pm | 3 +-
lib/PublicInbox/SearchIdxShard.pm | 14 ++--
lib/PublicInbox/Syscall.pm | 16 ++--
lib/PublicInbox/TestCommon.pm | 85 +++++++++----------
lib/PublicInbox/ViewVCS.pm | 12 ++-
lib/PublicInbox/WWW.pm | 4 +-
lib/PublicInbox/Watch.pm | 11 +--
lib/PublicInbox/XapClient.pm | 11 +--
lib/PublicInbox/XapHelper.pm | 24 ++----
lib/PublicInbox/XapHelperCxx.pm | 11 +--
lib/PublicInbox/Xapcmd.pm | 5 +-
lib/PublicInbox/xap_helper.h | 60 ++++++--------
script/public-inbox-convert | 8 +-
script/public-inbox-edit | 4 +-
script/public-inbox-init | 30 +++----
t/dir_idle.t | 2 +-
t/ds-leak.t | 4 +-
t/gcf2.t | 5 +-
t/init.t | 7 ++
t/lei-sigpipe.t | 7 +-
t/lei-up.t | 4 +-
xt/git-http-backend.t | 30 +++----
xt/mem-imapd-tls.t | 21 ++---
xt/mem-nntpd-tls.t | 8 +-
44 files changed, 335 insertions(+), 409 deletions(-)
^ permalink raw reply [relevance 7%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2023-10-17 23:37 7% [PATCH 00/30] autodie-ification and code simplifications Eric Wong
2023-10-17 23:38 6% ` [PATCH 23/30] init: use autodie to reduce distractions Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
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).