]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei q: reject remotes early if curl(1) is missing
authorEric Wong <e@80x24.org>
Mon, 25 Jan 2021 01:18:56 +0000 (17:18 -0800)
committerEric Wong <e@80x24.org>
Tue, 26 Jan 2021 18:51:31 +0000 (18:51 +0000)
This ought to provide a better user experience for
users if they attempt to use remote externals but
don't have curl installed.

We can avoid repeating PATH search in every worker here, too.

lib/PublicInbox/LeiXSearch.pm

index 68be8ada5045508efe16ec4b36ea1971f217f863..369f6f89ecc44b99b6c9e22ee72c0994b9ecc6dd 100644 (file)
@@ -14,7 +14,7 @@ use PublicInbox::Import;
 use File::Temp 0.19 (); # 0.19 for ->newdir
 use File::Spec ();
 use PublicInbox::Search qw(xap_terms);
-use PublicInbox::Spawn qw(popen_rd spawn);
+use PublicInbox::Spawn qw(popen_rd spawn which);
 use PublicInbox::MID qw(mids);
 use Fcntl qw(SEEK_SET F_SETFL O_APPEND O_RDWR);
 
@@ -192,7 +192,7 @@ sub query_remote_mboxrd {
        my ($opt, $env) = @$lei{qw(opt env)};
        my @qform = (q => $lei->{mset_opt}->{qstr}, x => 'm');
        push(@qform, t => 1) if $opt->{thread};
-       my @cmd = (qw(curl -sSf -d), '');
+       my @cmd = ($self->{curl}, qw(-sSf -d), '');
        my $verbose = $opt->{verbose};
        my $reap;
        my $cerr = File::Temp->new(TEMPLATE => 'curl.err-XXXX', TMPDIR => 1);
@@ -411,13 +411,22 @@ sub ipc_atfork_prepare {
        $self->SUPER::ipc_atfork_prepare; # PublicInbox::IPC
 }
 
+sub add_uri {
+       my ($self, $uri) = @_;
+       if (my $curl = $self->{curl} //= which('curl') // 0) {
+               push @{$self->{remotes}}, $uri;
+       } else {
+               warn "curl missing, ignoring $uri\n";
+       }
+}
+
 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 push(@{$self->{remotes}}, $loc) if $loc->can('scheme');
+               return add_uri($self, $loc) if $loc->can('scheme');
        } elsif ($loc =~ m!\Ahttps?://!) {
                require URI;
-               return push(@{$self->{remotes}}, URI->new($loc));
+               return add_uri($self, URI->new($loc));
        } elsif (-f "$loc/ei.lock") {
                require PublicInbox::ExtSearch;
                $loc = PublicInbox::ExtSearch->new($loc);