]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
cindex: basic inboxes are non-fatal for --associate
authorEric Wong <e@80x24.org>
Tue, 24 Oct 2023 11:44:29 +0000 (11:44 +0000)
committerEric Wong <e@80x24.org>
Tue, 24 Oct 2023 20:04:29 +0000 (20:04 +0000)
We need to gracefully continue when a user tries to associate
with --all but has basic (or completely unindexed) inboxes.

lib/PublicInbox/CodeSearchIdx.pm
t/cindex.t

index 2d1d8b223cd4e24df7e51aa236f8a01b78428e68..c8e4c591504cf34f18841fd2c3aff62adacfb6f4 100644 (file)
@@ -551,12 +551,14 @@ sub dump_roots_start {
 sub dump_ibx { # sends to xap_helper.h
        my ($self, $ibx_id) = @_;
        my $ibx = $IBX[$ibx_id] // die "BUG: no IBX[$ibx_id]";
-       my @cmd = ('dump_ibx', $ibx->isrch->xh_args,
-                       (map { ('-A', $_) } @ASSOC_PFX),
-                       $ibx_id, $QRY_STR);
+       my $ekey = $ibx->eidx_key;
+       my $srch = $ibx->isrch or return warn <<EOM;
+W: $ekey not indexed for search
+EOM
+       my @cmd = ('dump_ibx', $srch->xh_args,
+                       (map { ('-A', $_) } @ASSOC_PFX), $ibx_id, $QRY_STR);
        pipe(my $r, my $w);
        $XHC->mkreq([$DUMP_IBX_WPIPE, $w], @cmd);
-       my $ekey = $ibx->eidx_key;
        $self->{PENDING}->{$ekey} = $TODO{associate};
        PublicInbox::CidxXapHelperAux->new($r, $self, $ekey);
 }
index 51317329afbf85921c7e82511dc887ef28b031a3..c7de150541d9ca8234208a735b515ee5d8bf95f5 100644 (file)
@@ -198,4 +198,25 @@ SKIP: {
        ok(run_script([qw(-xcpdb --compact), "$tmp/ext"]), 'xcpdb compact');
 };
 
+my $basic = create_inbox 'basic', indexlevel => 'basic', sub {
+       my ($im, $ibx) = @_;
+       $im->add(eml_load('t/plack-qp.eml'));
+};
+{
+       my $env = { PI_CONFIG => "$tmp/pi_config" };
+       open my $fh, '>', $env->{PI_CONFIG};
+       print $fh <<EOM;
+[publicinbox "basictest"]
+       inboxdir = $basic->{inboxdir}
+       address = basic\@example.com
+EOM
+       close $fh;
+       my $cmd = [ qw(-cindex -u --all --associate -d), "$tmp/ext",
+               '-I', $basic->{inboxdir} ];
+       my $opt = { 1 => \(my $cidx_out), 2 => \(my $cidx_err) };
+       ok(run_script($cmd, $env, $opt), 'associate w/o search');
+       like($cidx_err, qr/W: \Q$basic->{inboxdir}\E not indexed for search/,
+               'non-Xapian-enabled inbox noted');
+}
+
 done_testing;