* [PATCH 02/30] lei_mirror: autodie most `close' calls
2023-10-17 23:37 7% [PATCH 00/30] autodie-ification and code simplifications Eric Wong
@ 2023-10-17 23:37 5% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2023-10-17 23:37 UTC (permalink / raw)
To: meta
Another step towards reducing our code burden and having
more consistent error messages.
---
lib/PublicInbox/LeiMirror.pm | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/lib/PublicInbox/LeiMirror.pm b/lib/PublicInbox/LeiMirror.pm
index f4c16a9d..84344f37 100644
--- a/lib/PublicInbox/LeiMirror.pm
+++ b/lib/PublicInbox/LeiMirror.pm
@@ -21,7 +21,7 @@ use PublicInbox::LeiCurl;
use PublicInbox::OnDestroy;
use PublicInbox::SHA qw(sha256_hex sha1_hex);
use POSIX qw(strftime);
-use autodie qw(chmod pipe readlink seek sysopen truncate unlink);
+use autodie qw(chmod close pipe readlink seek sysopen truncate unlink);
our $LIVE; # pid => callback
our $FGRP_TODO; # objstore -> [[ to resume ], [ to clone ]]
@@ -58,7 +58,7 @@ sub try_scrape {
my $opt = { 0 => $lei->{0}, 2 => $lei->{2} };
my $fh = popen_rd($cmd, undef, $opt);
my $html = do { local $/; <$fh> } // die "read(curl $uri): $!";
- close($fh) or return $lei->child_error($?, "@$cmd failed");
+ CORE::close($fh) or return $lei->child_error($?, "@$cmd failed");
# we grep with URL below, we don't want Subject/From headers
# making us clone random URLs. This assumes remote instances
@@ -295,7 +295,7 @@ sub start_update_ref {
qw(update-ref --stdin -z) ];
my $pack = PublicInbox::OnDestroy->new($$, \&satellite_done, $fgrp);
start_cmd($fgrp, $cmd, { 0 => $r, 2 => $fgrp->{lei}->{2} }, $pack);
- close $r or die "close(r): $!";
+ close $r;
$fgrp->{dry_run} ? undef : $w;
}
@@ -335,7 +335,7 @@ sub fgrp_update {
upr($lei, $w, 'create', $ref, $oid);
}
}
- close($w) or upref_warn();
+ CORE::close($w) or upref_warn();
}
sub satellite_done {
@@ -345,7 +345,7 @@ sub satellite_done {
while (my ($ref, $oid) = each %$create) {
upr($fgrp->{lei}, $w, 'create', $ref, $oid);
}
- close($w) or upref_warn();
+ CORE::close($w) or upref_warn();
} else {
pack_refs($fgrp, $fgrp->{cur_dst});
run_puh($fgrp);
@@ -463,7 +463,7 @@ sub fgrp_fetch_all {
(map { "\t$grp = $_->{-remote}\n" } @$old),
(map { "\t$grp = $_->{-remote}\n" } @$new));
print $fh $buf or die "print($f): $!";
- close $fh or die "close($f): $!";
+ close $fh;
unlink("$f.lock");
}
$cmd = [ @git, "--git-dir=$osdir", @fetch, $grp ];
@@ -490,7 +490,7 @@ sub forkgroup_prep {
[pack]
island = refs/remotes/([^/]+)/
EOM
- close $fh or die "close($f): $!";
+ close $fh;
}
my $key = $self->{-key} // die 'BUG: no -key';
my $rn = substr(sha256_hex($key), 0, 16);
@@ -507,7 +507,7 @@ EOM
; fetch = +refs/*:refs/*
; mirror = true
EOM
- close $fh or die "close($f): $!";
+ close $fh;
}
if (!$self->{dry_run}) {
my $alt = File::Spec->rel2abs("$dir/objects");
@@ -520,7 +520,7 @@ EOM
if (!grep(/\A\Q$l\E\z/, @cur)) {
say $fh $l or die "say($f): $!";
}
- close $fh or die "close($f): $!";
+ close $fh;
}
bless {
%$self, -osdir => $dir, -remote => $rn, -uri => $uri
@@ -712,7 +712,7 @@ EOM
owner = $ent->{owner}
EOM
}
- close $fh or die "close($f): $!";
+ close $fh;
my %map = (head => 'HEAD', description => undef);
while (my ($key, $fn) = each %map) {
my $val = $ent->{$key} // next;
@@ -720,7 +720,7 @@ EOM
$fn = "$edst/$fn";
open $fh, '>', $fn or die "open($fn): $!";
print $fh $val, "\n" or die "print($fn): $!";
- close $fh or die "close($fn): $!";
+ close $fh;
}
}
@@ -1395,7 +1395,7 @@ compact :
.PHONY : help fetch update index reindex compact
EOM
- close $fh or die "close($f): $!";
+ close $fh;
} else {
die "open($f): $!" unless $!{EEXIST};
}
^ permalink raw reply related [relevance 5%]
* [PATCH 00/30] autodie-ification and code simplifications
@ 2023-10-17 23:37 7% Eric Wong
2023-10-17 23:37 5% ` [PATCH 02/30] lei_mirror: autodie most `close' calls 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:37 5% ` [PATCH 02/30] lei_mirror: autodie most `close' calls 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).