From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 248E61FC9A for ; Sat, 6 Feb 2021 12:18:46 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 15/17] lei add-external: reject index and remote opts w/o mirror Date: Sat, 6 Feb 2021 12:18:42 +0000 Message-Id: <20210206121844.10979-16-e@80x24.org> In-Reply-To: <20210206121844.10979-1-e@80x24.org> References: <20210206121844.10979-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Option combinations which make no sense should fail to prevent misunderstandings and avoid surprises. --- lib/PublicInbox/LeiExternal.pm | 22 ++++++++++++++++++++-- t/lei-mirror.t | 6 ++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/PublicInbox/LeiExternal.pm b/lib/PublicInbox/LeiExternal.pm index 6a5c2517..b65dc87c 100644 --- a/lib/PublicInbox/LeiExternal.pm +++ b/lib/PublicInbox/LeiExternal.pm @@ -101,9 +101,27 @@ sub add_external_finish { sub lei_add_external { my ($self, $location) = @_; $self->_lei_store(1)->write_prepare($self); - my $new_boost = $self->{opt}->{boost} // 0; + my $opt = $self->{opt}; + my $mirror = $opt->{mirror} // do { + my @fail; + for my $sw ($self->index_opt, $self->curl_opt, + qw(c no-torsocks torsocks inbox-version)) { + my ($f) = (split(/|/, $sw, 2))[0]; + next unless defined $opt->{$f}; + $f = length($f) == 1 ? "-$f" : "--$f"; + push @fail, $f; + } + if (scalar(@fail) == 1) { + return $self->("@fail requires --mirror"); + } elsif (@fail) { + my $last = pop @fail; + my $fail = join(', ', @fail); + return $self->("@fail and $last require --mirror"); + } + undef; + }; + my $new_boost = $opt->{boost} // 0; $location = ext_canonicalize($location); - my $mirror = $self->{opt}->{mirror}; if (defined($mirror) && -d $location) { $self->fail(<<""); # TODO: did you mean "update-external?" --mirror destination `$location' already exists diff --git a/t/lei-mirror.t b/t/lei-mirror.t index cf34c7ae..6af49678 100644 --- a/t/lei-mirror.t +++ b/t/lei-mirror.t @@ -16,6 +16,12 @@ test_lei({ tmpdir => $tmpdir }, sub { my $t2 = "$home/t2-mirror"; ok($lei->('add-external', $t2, '--mirror', "$http/t2/"), '--mirror v2'); ok(-f "$t2/msgmap.sqlite3", 't2-mirror indexed'); + + ok(!$lei->('add-external', $t2, '--mirror', "$http/t2/"), + '--mirror fails if reused'); + + ok(!$lei->('add-external', "$t2-fail", '-Lmedium'), '--mirror v2'); + ok(!-d "$t2-fail", 'destination not created on failure'); }); ok($td->kill, 'killed -httpd');