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] lei_to_mail: don't close STDOUT unless it is a mbox* output
Date: Wed, 22 Nov 2023 00:13:31 +0000	[thread overview]
Message-ID: <20231122001331.1837369-1-e@80x24.org> (raw)

We only care about error checking when stdout is an mbox output
pointed to a pathname.  This is noticeable with `lei up' with
multiple non-mbox* destinations.  We'll also ensure throwing
exceptions to trigger lei->x_it from lei->do_env results in the
epoll/kqueue watch being discarded, otherwise commands may never
terminate (leading to stuck tests)
---
 lib/PublicInbox/LEI.pm       | 1 +
 lib/PublicInbox/LeiToMail.pm | 4 ++--
 t/lei-q-save.t               | 2 ++
 3 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index 8d235b37..86b71fcd 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -493,6 +493,7 @@ sub x_it ($$) {
 	} elsif ($quit == \&CORE::exit) { # an admin (one-shot) command
 		exit($code >> 8);
 	} # else ignore if client disconnected
+	$self->dclose if $$ == $daemon_pid;
 }
 
 sub err ($;@) {
diff --git a/lib/PublicInbox/LeiToMail.pm b/lib/PublicInbox/LeiToMail.pm
index 007191bb..a930fc30 100644
--- a/lib/PublicInbox/LeiToMail.pm
+++ b/lib/PublicInbox/LeiToMail.pm
@@ -612,8 +612,8 @@ sub _pre_augment_mbox {
 sub finish_output {
 	my ($self, $lei) = @_;
 	my $out = delete $lei->{1} // die 'BUG: no lei->{1}';
-	my $old = delete $lei->{old_1};
-	$lei->{1} = $old if $old;
+	my $old = delete $lei->{old_1} or return; # path only
+	$lei->{1} = $old;
 	return if $out->close; # reaps gzip|pigz|xz|bzip2
 	my $msg = "E: Error closing $lei->{ovv}->{dst}";
 	$? ? $lei->child_error($?) : ($msg .= " ($!)");
diff --git a/t/lei-q-save.t b/t/lei-q-save.t
index a9f9d4d6..0970bc3c 100644
--- a/t/lei-q-save.t
+++ b/t/lei-q-save.t
@@ -305,5 +305,7 @@ EOM
 	is(scalar(@new), 2, 'got new message');
 	is_xdeeply([grep { $_ eq $orig[0] } @new], \@orig,
 		'original message preserved on up w/ threads');
+	lei_ok 'up', "$home/md", $d, \'multiple maildir up';
+	unlike $lei_err, qr! line \d+!s, 'no warnings';
 });
 done_testing;

                 reply	other threads:[~2023-11-22  0:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20231122001331.1837369-1-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).