]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LEI.pm
lei q: -I/--exclude/--only support globs and basenames
[public-inbox.git] / lib / PublicInbox / LEI.pm
index 2c512c5eb545084f902aa221e8af6808cd6c9340..3cb7a32779f168e7fbdae1e141d39da20fb4d22a 100644 (file)
@@ -104,7 +104,7 @@ our %CMD = ( # sorted in order of importance/use:
 'q' => [ 'SEARCH_TERMS...', 'search for messages matching terms', qw(
        save-as=s output|mfolder|o=s format|f=s dedupe|d=s thread|t augment|a
        sort|s=s reverse|r offset=i remote! local! external! pretty
-       include|I=s@ exclude=s@ only=s@
+       include|I=s@ exclude=s@ only=s@ jobs|j=s globoff|g
        mua-cmd|mua=s no-torsocks torsocks=s verbose|v quiet|q
        received-after=s received-before=s sent-after=s sent-since=s),
        PublicInbox::LeiQuery::curl_opt(), opt_dash('limit|n=i', '[0-9]+') ],
@@ -201,6 +201,7 @@ my $ls_format = [ 'OUT|plain|json|null', 'listing output format' ];
 my %OPTDESC = (
 'help|h' => 'show this built-in help',
 'quiet|q' => 'be quiet',
+'globoff|g' => "do not match locations using '*?' wildcards and '[]' ranges",
 'verbose|v' => 'be more verbose',
 'solve!' => 'do not attempt to reconstruct blobs from emails',
 'torsocks=s' => ['auto|no|yes',
@@ -236,6 +237,9 @@ my %OPTDESC = (
 'q     only=s@' => [ 'URL_OR_PATHNAME',
                'only use specified external(s) for search' ],
 
+'q     jobs=s' => [ '[SEARCH_JOBS][,WRITER_JOBS]',
+               'control number of search and writer jobs' ],
+
 'ls-query      format|f=s' => $ls_format,
 'ls-external   format|f=s' => $ls_format,
 
@@ -282,8 +286,8 @@ sub x_it ($$) {
        # make sure client sees stdout before exit
        $self->{1}->autoflush(1) if $self->{1};
        dump_and_clear_log();
-       if (my $sock = $self->{sock}) {
-               send($sock, "x_it $code", MSG_EOR);
+       if (my $s = $self->{pkt_op} // $self->{sock}) {
+               send($s, "x_it $code", MSG_EOR);
        } elsif ($self->{oneshot}) {
                # don't want to end up using $? from child processes
                for my $f (qw(lxs l2m)) {
@@ -305,12 +309,12 @@ sub x_it ($$) {
 sub err ($;@) {
        my $self = shift;
        my $err = $self->{2} // ($self->{pgr} // [])->[2] // *STDERR{GLOB};
-       my $eor = (substr($_[-1], -1, 1) eq "\n" ? () : "\n");
-       print $err @_, $eor and return;
+       my @eor = (substr($_[-1]//'', -1, 1) eq "\n" ? () : ("\n"));
+       print $err @_, @eor and return;
        my $old_err = delete $self->{2};
-       close($old_err) if $! == EPIPE && $old_err;;
+       close($old_err) if $! == EPIPE && $old_err;
        $err = $self->{2} = ($self->{pgr} // [])->[2] // *STDERR{GLOB};
-       print $err @_, $eor or print STDERR @_, $eor;
+       print $err @_, @eor or print STDERR @_, @eor;
 }
 
 sub qerr ($;@) { $_[0]->{opt}->{quiet} or err(shift, @_) }
@@ -336,9 +340,10 @@ sub puts ($;@) { out(shift, map { "$_\n" } @_) }
 
 sub child_error { # passes non-fatal curl exit codes to user
        my ($self, $child_error) = @_; # child_error is $?
-       if (my $sock = $self->{sock}) { # send to lei(1) client
-               send($sock, "child_error $child_error", MSG_EOR);
-       } elsif ($self->{oneshot}) {
+       if (my $s = $self->{pkt_op} // $self->{sock}) {
+               # send to the parent lei-daemon or to lei(1) client
+               send($s, "child_error $child_error", MSG_EOR);
+       } elsif (!$PublicInbox::DS::in_loop) {
                $self->{child_error} = $child_error;
        } # else noop if client disconnected
 }
@@ -417,9 +422,9 @@ sub atfork_parent_wq {
                $lei->{$f} = $wq->deep_clone($tmp);
        }
        $self->{env} = $env;
-       delete @$lei{qw(3 -lei_store cfg old_1 pgr lxs)}; # keep l2m
+       delete @$lei{qw(sock 3 -lei_store cfg old_1 pgr lxs)}; # keep l2m
        my @io = (delete(@$lei{qw(0 1 2)}),
-                       io_extract($lei, qw(sock pkt_op startq)));
+                       io_extract($lei, qw(pkt_op startq)));
        my $l2m = $lei->{l2m};
        if ($l2m && $l2m != $wq) { # $wq == lxs
                if (my $wq_s1 = $l2m->{-wq_s1}) {