]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LeiXSearch.pm
No ext_urls
[public-inbox.git] / lib / PublicInbox / LeiXSearch.pm
index 90cb83b989feb6c1099b1213ff2937c2a0b38c2a..5965274ca211396df49e263ec6ade1508e3ba458 100644 (file)
@@ -400,9 +400,8 @@ sub query_remote_mboxrd {
 
 sub git { $_[0]->{git} // die 'BUG: git uninitialized' }
 
-sub xsearch_done_wait { # dwaitpid callback
-       my ($arg, $pid) = @_;
-       my ($wq, $lei) = @$arg;
+sub xsearch_done_wait { # awaitpid cb
+       my ($pid, $wq, $lei) = @_;
        return if !$?;
        my $s = $? & 127;
        return $lei->child_error($?) if $s == 13 || $s == 15;
@@ -574,15 +573,15 @@ sub do_query {
                        $l2m->{au_peers} = [ $a_r, $a_w, $b_r, $b_w ];
                }
                $l2m->wq_workers_start('lei2mail', undef,
-                                       $lei->oldset, { lei => $lei });
-               $l2m->wq_wait_async(\&xsearch_done_wait, $lei);
+                                       $lei->oldset, { lei => $lei },
+                                       \&xsearch_done_wait, $lei);
                pipe($lei->{startq}, $lei->{au_done}) or die "pipe: $!";
                fcntl($lei->{startq}, $F_SETPIPE_SZ, 4096) if $F_SETPIPE_SZ;
                delete $l2m->{au_peers};
        }
        $self->wq_workers_start('lei_xsearch', undef,
-                               $lei->oldset, { lei => $lei });
-       $self->wq_wait_async(\&xsearch_done_wait, $lei);
+                               $lei->oldset, { lei => $lei },
+                               \&xsearch_done_wait, $lei);
        my $op_c = delete $lei->{pkt_op_c};
        delete $lei->{pkt_op_p};
        @$end = ();
@@ -605,34 +604,40 @@ sub add_uri {
                require IO::Uncompress::Gunzip;
                require PublicInbox::LeiCurl;
                push @{$self->{remotes}}, $uri;
+               $uri;
        } else {
                warn "curl missing, ignoring $uri\n";
+               undef;
        }
 }
 
+# returns URI or PublicInbox::Inbox-like object
 sub prepare_external {
        my ($self, $loc, $boost) = @_; # n.b. already ordered by boost
        if (ref $loc) { # already a URI, or PublicInbox::Inbox-like object
                return add_uri($self, $loc) if $loc->can('scheme');
+               # fall-through on Inbox-like objects
        } elsif ($loc =~ m!\Ahttps?://!) {
                require URI;
                return add_uri($self, URI->new($loc));
-       } elsif (-f "$loc/ei.lock") {
+       } elsif (-f "$loc/ei.lock" && -d "$loc/ALL.git/objects") {
                require PublicInbox::ExtSearch;
                die "`\\n' not allowed in `$loc'\n" if index($loc, "\n") >= 0;
                $loc = PublicInbox::ExtSearch->new($loc);
-       } elsif (-f "$loc/inbox.lock" || -d "$loc/public-inbox") {
+       } elsif ((-f "$loc/inbox.lock" && -d "$loc/all.git/objects") ||
+                       (-d "$loc/public-inbox" && -d "$loc/objects")) {
                die "`\\n' not allowed in `$loc'\n" if index($loc, "\n") >= 0;
                require PublicInbox::Inbox; # v2, v1
                $loc = bless { inboxdir => $loc }, 'PublicInbox::Inbox';
        } elsif (!-e $loc) {
                warn "W: $loc gone, perhaps run: lei forget-external $loc\n";
-               return;
+               return undef;
        } else {
                warn "W: $loc ignored, unable to determine external type\n";
-               return;
+               return undef;
        }
        push @{$self->{locals}}, $loc;
+       $loc;
 }
 
 sub _lcat_i { # LeiMailSync->each_src iterator callback