From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id B84341FB06 for ; Fri, 3 Sep 2021 08:54:27 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 5/8] lei up --all: avoid double-close on shared STDOUT Date: Fri, 3 Sep 2021 08:54:24 +0000 Message-Id: <20210903085427.5541-6-e@80x24.org> In-Reply-To: <20210903085427.5541-1-e@80x24.org> References: <20210903085427.5541-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 | 1 + lib/PublicInbox/LeiUp.pm | 4 ++++ t/lei-up.t | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 t/lei-up.t 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;