unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
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	[thread overview]
Message-ID: <20210903085427.5541-6-e@80x24.org> (raw)
In-Reply-To: <20210903085427.5541-1-e@80x24.org>

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 <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;

  parent reply	other threads:[~2021-09-03  8:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-03  8:54 [PATCH 0/8] lei: fix IMAP R/W; L/kw false positives Eric Wong
2021-09-03  8:54 ` [PATCH 1/8] lei: dump errors to syslog, and not to CLI Eric Wong
2021-09-03  8:54 ` [PATCH 2/8] lei/store: quiet down link(2) warnings Eric Wong
2021-09-03  8:54 ` [PATCH 3/8] lei: ->child_error less error-prone Eric Wong
2021-09-03  8:54 ` [PATCH 4/8] lei: use lei->lms in place of lse->lms in a few places Eric Wong
2021-09-03  8:54 ` Eric Wong [this message]
2021-09-03  8:54 ` [PATCH 6/8] lei inspect: support reading eml from --stdin Eric Wong
2021-09-03  8:54 ` [PATCH 7/8] lei_xsearch: avoid false-positives on externals w/ L: and kw: Eric Wong
2021-09-03  8:54 ` [PATCH 8/8] lei: fix read/write IMAP access Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210903085427.5541-6-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).