]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei add-external: reject index and remote opts w/o mirror
authorEric Wong <e@80x24.org>
Sat, 6 Feb 2021 12:18:42 +0000 (12:18 +0000)
committerEric Wong <e@80x24.org>
Sun, 7 Feb 2021 03:34:32 +0000 (03:34 +0000)
Option combinations which make no sense should fail
to prevent misunderstandings and avoid surprises.

lib/PublicInbox/LeiExternal.pm
t/lei-mirror.t

index 6a5c2517b62db3cff539762b4d202d94894fe592..b65dc87c7b0f312b6fdb143d67c96e3a0dc68779 100644 (file)
@@ -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
index cf34c7ae11074dd61122bc385c7c5bcf20dae736..6af49678468b31ea401c863985ea513f3efbd562 100644 (file)
@@ -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');