]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei up --all: avoid double-close on shared STDOUT
authorEric Wong <e@80x24.org>
Fri, 3 Sep 2021 08:54:24 +0000 (08:54 +0000)
committerEric Wong <e@80x24.org>
Fri, 3 Sep 2021 08:57:34 +0000 (08:57 +0000)
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.

MANIFEST
lib/PublicInbox/LeiUp.pm
t/lei-up.t [new file with mode: 0644]

index be6ec9279e6c3549e6e140cde95ce9e8c91f80b1..fad2962225fc914e8512b72c459edc2ae30c5c5d 100644 (file)
--- 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
index e1da64aa3847e766a1b983af97b6aa14ebba1660..a39d6047a26cab1c5e7db999271118f5b513aabe 100644 (file)
@@ -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 (file)
index 0000000..c6f31c7
--- /dev/null
@@ -0,0 +1,39 @@
+#!perl -w
+# Copyright all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+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;