From: Eric Wong Date: Fri, 3 Sep 2021 08:54:24 +0000 (+0000) Subject: lei up --all: avoid double-close on shared STDOUT X-Git-Tag: v1.7.0~451 X-Git-Url: http://www.git.stargrave.org/?p=public-inbox.git;a=commitdiff_plain;h=059f92ef0d66677cce0b0d011748f7fcc1697a51;hp=7e29f0aa79e3e559379ebfa8bb8b17eabdb6db1a lei up --all: avoid double-close on shared STDOUT This is merely to avoid perl setting errors internally which were not user visible. The double-close wasn't a problem in practice since we open a new file hanlde for the mbox or mbox.gz anyways, so the new t/lei-up.t test case shows no regressions nor fixes. --- diff --git a/MANIFEST b/MANIFEST index be6ec927..fad29622 100644 --- a/MANIFEST +++ b/MANIFEST @@ -443,6 +443,7 @@ t/lei-q-save.t t/lei-q-thread.t t/lei-sigpipe.t t/lei-tag.t +t/lei-up.t t/lei-watch.t t/lei.t t/lei_dedupe.t diff --git a/lib/PublicInbox/LeiUp.pm b/lib/PublicInbox/LeiUp.pm index e1da64aa..a39d6047 100644 --- a/lib/PublicInbox/LeiUp.pm +++ b/lib/PublicInbox/LeiUp.pm @@ -54,6 +54,10 @@ sub up1_redispatch { $l->{opt} = { %{$l->{opt}} }; delete $l->{sock}; $l->{''} = $op_p; # daemon only + + # make close($l->{1}) happy in lei->dclose + open my $fh, '>&', $l->{1} or return $l->child_error(0, "dup: $!"); + $l->{1} = $fh; eval { $l->qerr("# updating $out"); up1($l, $out); diff --git a/t/lei-up.t b/t/lei-up.t new file mode 100644 index 00000000..c6f31c74 --- /dev/null +++ b/t/lei-up.t @@ -0,0 +1,39 @@ +#!perl -w +# Copyright all contributors +# License: AGPL-3.0+ +use strict; use v5.10.1; use PublicInbox::TestCommon; +my ($ro_home, $cfg_path) = setup_public_inboxes; +use IO::Uncompress::Gunzip qw(gunzip $GunzipError); +test_lei(sub { + my $s = eml_load('t/plack-qp.eml')->as_string; + lei_ok [qw(import -q -F eml -)], undef, { 0 => \$s, %$lei_opt }; + lei_ok qw(q z:0.. -f mboxcl2 -o), "$ENV{HOME}/a.mbox.gz"; + lei_ok qw(q z:0.. -f mboxcl2 -o), "$ENV{HOME}/b.mbox.gz"; + lei_ok qw(q z:0.. -f mboxcl2 -o), "$ENV{HOME}/a"; + lei_ok qw(q z:0.. -f mboxcl2 -o), "$ENV{HOME}/b"; + lei_ok qw(ls-search); + $s = eml_load('t/utf8.eml')->as_string; + lei_ok [qw(import -q -F eml -)], undef, { 0 => \$s, %$lei_opt }; + lei_ok qw(up --all=local); + open my $fh, "$ENV{HOME}/a.mbox.gz" or xbail "open: $!"; + my $gz = do { local $/; <$fh> }; + my $uc; + gunzip(\$gz => \$uc, MultiStream => 1) or xbail "gunzip $GunzipError"; + open $fh, "$ENV{HOME}/a" or xbail "open: $!"; + + my $exp = do { local $/; <$fh> }; + is($uc, $exp, 'compressed and uncompressed match (a.gz)'); + like($exp, qr/testmessage\@example.com/, '2nd message added'); + open $fh, "$ENV{HOME}/b.mbox.gz" or xbail "open: $!"; + + $gz = do { local $/; <$fh> }; + undef $uc; + gunzip(\$gz => \$uc, MultiStream => 1) or xbail "gunzip $GunzipError"; + is($uc, $exp, 'compressed and uncompressed match (b.gz)'); + + open $fh, "$ENV{HOME}/b" or xbail "open: $!"; + $uc = do { local $/; <$fh> }; + is($uc, $exp, 'uncompressed both match'); +}); + +done_testing;