From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 4/5] lei q: reject remotes early if curl(1) is missing
Date: Sun, 24 Jan 2021 17:18:56 -0800 [thread overview]
Message-ID: <20210125011857.563-5-e@80x24.org> (raw)
In-Reply-To: <20210125011857.563-1-e@80x24.org>
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 | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/lib/PublicInbox/LeiXSearch.pm b/lib/PublicInbox/LeiXSearch.pm
index 68be8ada..369f6f89 100644
--- a/lib/PublicInbox/LeiXSearch.pm
+++ b/lib/PublicInbox/LeiXSearch.pm
@@ -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);
next prev parent reply other threads:[~2021-01-25 1:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-25 1:18 [PATCH 0/5] lei: more fixes and usability enhancement Eric Wong
2021-01-25 1:18 ` [PATCH 1/5] lei: reinstate JSON smsg output deduplication Eric Wong
2021-01-25 1:18 ` [PATCH 2/5] lei q: drop "oid" output format Eric Wong
2021-01-25 1:18 ` [PATCH 3/5] lei q: demangle and quiet curl output Eric Wong
2021-01-25 1:18 ` Eric Wong [this message]
2021-01-25 1:18 ` [PATCH 5/5] lei q: continue remote search if torsocks(1) is missing Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210125011857.563-5-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).