diff options
Diffstat (limited to 'lib/PublicInbox/LeiRemote.pm')
-rw-r--r-- | lib/PublicInbox/LeiRemote.pm | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/lib/PublicInbox/LeiRemote.pm b/lib/PublicInbox/LeiRemote.pm index 346aa6a4..d6fc40a4 100644 --- a/lib/PublicInbox/LeiRemote.pm +++ b/lib/PublicInbox/LeiRemote.pm @@ -1,4 +1,4 @@ -# Copyright (C) 2021 all contributors <meta@public-inbox.org> +# Copyright (C) all contributors <meta@public-inbox.org> # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt> # Make remote externals HTTP(S) inboxes behave like @@ -9,7 +9,6 @@ package PublicInbox::LeiRemote; use v5.10.1; use strict; use IO::Uncompress::Gunzip; -use PublicInbox::OnDestroy; use PublicInbox::MboxReader; use PublicInbox::Spawn qw(popen_rd); use PublicInbox::LeiCurl; @@ -22,7 +21,7 @@ sub new { sub isrch { $_[0] } # SolverGit expcets this -sub _each_mboxrd_eml { # callback for MboxReader->mboxrd +sub each_mboxrd_eml { # callback for MboxReader->mboxrd my ($eml, $self) = @_; my $lei = $self->{lei}; my $xoids = $lei->{ale}->xoids_for($eml, 1); @@ -47,17 +46,13 @@ sub mset { $uri->query_form(q => $qstr, x => 'm', r => 1); # r=1: relevance my $cmd = $curl->for_uri($self->{lei}, $uri); $self->{lei}->qerr("# $cmd"); - my $rdr = { 2 => $lei->{2}, pgid => 0 }; - my ($fh, $pid) = popen_rd($cmd, undef, $rdr); - my $reap = PublicInbox::OnDestroy->new($lei->can('sigint_reap'), $pid); $self->{smsg} = []; - $fh = IO::Uncompress::Gunzip->new($fh, MultiStream => 1); - PublicInbox::MboxReader->mboxrd($fh, \&_each_mboxrd_eml, $self); - my $err = waitpid($pid, 0) == $pid ? undef - : "BUG: waitpid($cmd): $!"; - @$reap = (); # cancel OnDestroy - my $wait = $self->{lei}->{sto}->wq_do('done'); - die $err if $err; + my $fh = popen_rd($cmd, undef, { 2 => $lei->{2} }); + $fh = IO::Uncompress::Gunzip->new($fh, MultiStream=>1, AutoClose=>1); + eval { PublicInbox::MboxReader->mboxrd($fh, \&each_mboxrd_eml, $self) }; + my $err = $@ ? ": $@" : ''; + my $wait = $self->{lei}->{sto}->wq_do('barrier'); + $lei->child_error($?, "@$cmd failed$err") if $err || $?; $self; # we are the mset (and $ibx, and $self) } @@ -72,10 +67,17 @@ sub base_url { "$_[0]->{uri}" } sub smsg_eml { my ($self, $smsg) = @_; - if (my $bref = $self->{lei}->ale->git->cat_file($smsg->{blob})) { - return PublicInbox::Eml->new($bref); - } - $self->{lei}->err("E: $self->{uri} $smsg->{blob} gone <$smsg->{mid}>"); + my $bref = $self->{lei}->ale->git->cat_file($smsg->{blob}) // do { + my $lms = $self->{lei}->lms; + ($lms ? $lms->local_blob($smsg->{blob}, 1) : undef) // do { + my $sto = $self->{lei}->{sto} // + $self->{lei}->_lei_store; + $sto && $sto->{-wq_s1} ? + $sto->wq_do('cat_blob', $smsg->{blob}) : undef; + } + }; + return PublicInbox::Eml->new($bref) if $bref; + warn("E: $self->{uri} $smsg->{blob} gone <$smsg->{mid}>\n"); undef; } |