From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 8819C1F560 for ; Sun, 24 Sep 2023 05:42:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1695534134; bh=dFpx57KnZmBEmkooBIfruhHhtPhe585s1Hf6ttdpUuA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=GwPuFbflBvNlBFxjb00Rt1150kaqqRNO5ZAOQMpZq3z8r0p6fdt4sa0WBrF36uJw3 lnccF2M2k8aFyVnlf6kevlU59MTnqxopsvM5FJjyuPzf9GFTv0PiIy8edvoJxOFh63 ZTFkWv0dzvmLNh0XGttv2NF5qY5yT5K+P3jxokCc= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/6] lei: check git-config(1) failures Date: Sun, 24 Sep 2023 05:42:09 +0000 Message-ID: <20230924054214.3539091-2-e@80x24.org> In-Reply-To: <20230924054214.3539091-1-e@80x24.org> References: <20230924054214.3539091-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 2020-2021 were bad times and I somehow got deluded into believing git-config(1) would always succeed :x --- lib/PublicInbox/LEI.pm | 9 ++++++--- lib/PublicInbox/LeiAddWatch.pm | 7 ++++--- lib/PublicInbox/LeiForgetExternal.pm | 3 +-- lib/PublicInbox/LeiInit.pm | 4 ++-- lib/PublicInbox/LeiRmWatch.pm | 2 +- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index 368f9357..a6d92eec 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -776,9 +776,8 @@ EOM /\A([^=\.]+\.[^=]+)(?:=(.*))?\z/ or return fail($self, <=' EOM - my $name = $1; - my $value = $2 // 1; - _config($self, '--add', $name, $value); + my ($name, $value) = ($1, $2 // 1); + _config($self, '--add', $name, $value) or return; if (defined(my $v = $tmp->{$name})) { if (ref($v) eq 'ARRAY') { push @$v, $value; @@ -894,13 +893,17 @@ sub _lei_store ($;$) { }; } +# returns true on success, undef +# argv[0] eq `+e' means errors do not ->fail # (like `sh +e') sub _config { my ($self, @argv) = @_; + my $err_ok = ($argv[0] // '') eq '+e' ? shift(@argv) : undef; my %env = (%{$self->{env}}, GIT_CONFIG => undef); my $cfg = _lei_cfg($self, 1); my $cmd = [ qw(git config -f), $cfg->{'-f'}, @argv ]; my %rdr = map { $_ => $self->{$_} } (0..2); waitpid(spawn($cmd, \%env, \%rdr), 0); + $? == 0 ? 1 : ($err_ok ? undef : fail($self, $?)); } sub lei_daemon_pid { puts shift, $$ } diff --git a/lib/PublicInbox/LeiAddWatch.pm b/lib/PublicInbox/LeiAddWatch.pm index 97e7a342..f61e2de4 100644 --- a/lib/PublicInbox/LeiAddWatch.pm +++ b/lib/PublicInbox/LeiAddWatch.pm @@ -26,13 +26,14 @@ sub lei_add_watch { for my $w (@{$self->{inputs}}) { # clobber existing, allow multiple if (defined($vmd0)) { - $lei->_config("watch.$w.vmd", '--replace-all', $vmd0); + $lei->_config("watch.$w.vmd", '--replace-all', $vmd0) + or return; for my $v (@vmd) { - $lei->_config("watch.$w.vmd", $v); + $lei->_config("watch.$w.vmd", $v) or return; } } next if defined $cfg->{"watch.$w.state"}; - $lei->_config("watch.$w.state", $state); + $lei->_config("watch.$w.state", $state) or return; } $lei->_lei_store(1); # create $lei->lms(1)->lms_write_prepare->add_folders(@{$self->{inputs}}); diff --git a/lib/PublicInbox/LeiForgetExternal.pm b/lib/PublicInbox/LeiForgetExternal.pm index 39bfc60b..c8d1df38 100644 --- a/lib/PublicInbox/LeiForgetExternal.pm +++ b/lib/PublicInbox/LeiForgetExternal.pm @@ -16,8 +16,7 @@ sub lei_forget_external { next if $seen{$l}++; my $key = "external.$l.boost"; delete($cfg->{$key}); - $lei->_config('--unset', $key); - if ($? == 0) { + if ($lei->_config('+e', '--unset', $key)) { $lei->qerr("# $l forgotten "); } elsif (($? >> 8) == 5) { warn("# $l not found\n"); diff --git a/lib/PublicInbox/LeiInit.pm b/lib/PublicInbox/LeiInit.pm index 27ce8169..94897e61 100644 --- a/lib/PublicInbox/LeiInit.pm +++ b/lib/PublicInbox/LeiInit.pm @@ -23,7 +23,7 @@ sub lei_init { # some folks like symlinks and bind mounts :P if (@dir && "@cur[1,0]" eq "@dir[1,0]") { - $self->_config('leistore.dir', $dir); + $self->_config('leistore.dir', $dir) or return; $self->_lei_store(1)->done; return $self->qerr("$exists (as $cur)"); } @@ -31,7 +31,7 @@ sub lei_init { E: leistore.dir=$cur already initialized and it is not $dir } - $self->_config('leistore.dir', $dir); + $self->_config('leistore.dir', $dir) or return; $self->_lei_store(1)->done; $exists //= "# leistore.dir=$dir newly initialized"; $self->qerr($exists); diff --git a/lib/PublicInbox/LeiRmWatch.pm b/lib/PublicInbox/LeiRmWatch.pm index c0f336f0..19bee3ab 100644 --- a/lib/PublicInbox/LeiRmWatch.pm +++ b/lib/PublicInbox/LeiRmWatch.pm @@ -14,7 +14,7 @@ sub lei_rm_watch { my $self = bless { missing_ok => 1 }, __PACKAGE__; $self->prepare_inputs($lei, \@argv) or return; for my $w (@{$self->{inputs}}) { - $lei->_config('--remove-section', "watch.$w"); + $lei->_config('--remove-section', "watch.$w") or return; } delete $lei->{cfg}; # force reload $lei->refresh_watches;