From: Eric Wong Date: Sun, 24 Sep 2023 05:42:09 +0000 (+0000) Subject: lei: check git-config(1) failures X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e3455d2f3b100a13cbf7cfe6b36619096a2c4e8a;p=thirdparty%2Fpublic-inbox.git lei: check git-config(1) failures 2020-2021 were bad times and I somehow got deluded into believing git-config(1) would always succeed :x --- diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index 368f93573..a6d92eec5 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 97e7a3422..f61e2de4f 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 39bfc60bc..c8d1df387 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 27ce81690..94897e61d 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 c0f336f02..19bee3ab6 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;