# we open this in the parent process before ->wq_io_do handoff
sub ovv_out_lk_init ($) {
my ($self) = @_;
- my $tmp = File::Temp->new("lei-ovv.dst.$$.lock-XXXXXX",
+ my $tmp = File::Temp->new("lei-ovv.dst.$$.lock-XXXX",
TMPDIR => 1, UNLINK => 0);
$self->{"lk_id.$self.$$"} = $self->{lock_path} = $tmp->filename;
}
--$ofmt_key=$fmt and --output=$ofmt conflict
}
- $fmt //= 'json' if $dst eq '/dev/stdout';
- $fmt //= detect_fmt($lei, $dst) or return;
+
+ my $devfd = $lei->path_to_fd($dst) // return;
+ $fmt //= $devfd >= 0 ? 'json' : (detect_fmt($lei, $dst) or return);
if (index($dst, '://') < 0) { # not a URL, so assume path
- $dst = File::Spec->canonpath($dst);
+ $dst = $lei->canonpath_harder($dst);
} # else URL
my $self = bless { fmt => $fmt, dst => $dst }, $class;
if ($fmt =~ /\A($JSONL|(?:concat)?json)\z/) {
$json = $self->{json} = ref(PublicInbox::Config->json);
}
- if ($dst eq '/dev/stdout') {
- my $isatty = $lei->{need_pager} = -t $lei->{1};
+ if ($devfd >= 0) {
+ my $isatty = $lei->{need_pager} = -t $lei->{$devfd};
$opt->{pretty} //= $isatty;
if (!$isatty && -f _) {
- my $fl = fcntl($lei->{1}, F_GETFL, 0) //
+ my $fl = fcntl($lei->{$devfd}, F_GETFL, 0) //
return $lei->fail("fcntl(stdout): $!");
ovv_out_lk_init($self) unless ($fl & O_APPEND);
} else {
if ($json) {
$lei->{dedupe} //= PublicInbox::LeiDedupe->new($lei);
} else {
- # default to the cheapest sort since MUA usually resorts
- $opt->{'sort'} //= 'docid' if $dst ne '/dev/stdout';
$lei->{l2m} = eval { PublicInbox::LeiToMail->new($lei) };
return $lei->fail($@) if $@;
if ($opt->{mua} && $lei->{l2m}->lock_free) {
$opt->{alert} //= [ ':WINCH,:bell' ] if -t $lei->{1};
}
}
+ return $lei->fail('--shared is only for v2 inbox output') if
+ $self->{fmt} ne 'v2' && $lei->{opt}->{shared};
$self;
}
} # TODO HTML/Atom/...
}
-# called once by parent (via PublicInbox::EOFpipe)
+# called once by parent (via PublicInbox::PktOp '' => query_done)
sub ovv_end {
my ($self, $lei) = @_;
if ($self->{fmt} eq 'json') {
}
sub ovv_each_smsg_cb { # runs in wq worker usually
- my ($self, $lei, $ibxish) = @_;
+ my ($self, $lei) = @_;
my ($json, $dedupe);
if (my $pkg = $self->{json}) {
$json = $pkg->new;
$dedupe->prepare_dedupe;
}
$lei->{ovv_buf} = \(my $buf = '') if !$l2m;
- if ($l2m && !$ibxish) { # remote https?:// mboxrd
- my $wcb = $l2m->write_cb($lei);
+ if ($l2m) {
sub {
- my ($smsg, undef, $eml) = @_; # no mitem in $_[1]
- $wcb->(undef, $smsg, $eml);
- };
- } elsif ($l2m && $l2m->{-wq_s1}) {
- sub {
- my ($smsg, $mitem) = @_;
+ my ($smsg, $mitem, $eml) = @_;
$smsg->{pct} = get_pct($mitem) if $mitem;
- $l2m->wq_io_do('write_mail', [], $smsg);
+ $l2m->wq_io_do('write_mail', [], $smsg, $eml);
}
} elsif ($self->{fmt} =~ /\A(concat)?json\z/ && $lei->{opt}->{pretty}) {
my $EOR = ($1//'') eq 'concat' ? "\n}" : "\n},";
- my $lse = $lei->{sto}->search;
+ my $lse = $lei->{lse};
sub { # DIY prettiness :P
my ($smsg, $mitem) = @_;
return if $dedupe->is_smsg_dup($smsg);
- $lse->xsmsg_vmd($smsg);
+ $lse->xsmsg_vmd($smsg, $smsg->{L} ? undef : 1);
$smsg = _unbless_smsg($smsg, $mitem);
$buf .= "{\n";
$buf .= join(",\n", map {
}
} elsif ($json) {
my $ORS = $self->{fmt} eq 'json' ? ",\n" : "\n"; # JSONL
- my $lse = $lei->{sto}->search;
+ my $lse = $lei->{lse};
sub {
my ($smsg, $mitem) = @_;
return if $dedupe->is_smsg_dup($smsg);
- $lse->xsmsg_vmd($smsg);
+ $lse->xsmsg_vmd($smsg, $smsg->{L} ? undef : 1);
$buf .= $json->encode(_unbless_smsg(@_)) . $ORS;
return if length($buf) < 65536;
my $lk = $self->lock_for_scope;