user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 05/10] lei_mirror: don't show success on failure
Date: Thu, 25 Mar 2021 06:20:21 +0200	[thread overview]
Message-ID: <20210325042026.11270-6-e@80x24.org> (raw)
In-Reply-To: <20210325042026.11270-1-e@80x24.org>

While we were exiting with a error code, showing a successful
"# mirrored $URL" message is misleading and wrong.  Don't show
success until everything is complete and the config is written.
---
 lib/PublicInbox/LeiMirror.pm | 11 ++++++++---
 t/lei-mirror.t               | 18 ++++++++++++++++++
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/lib/PublicInbox/LeiMirror.pm b/lib/PublicInbox/LeiMirror.pm
index d68cd6c1..c83386c6 100644
--- a/lib/PublicInbox/LeiMirror.pm
+++ b/lib/PublicInbox/LeiMirror.pm
@@ -12,8 +12,14 @@ use PublicInbox::Spawn qw(popen_rd spawn);
 sub do_finish_mirror { # dwaitpid callback
 	my ($arg, $pid) = @_;
 	my ($mrr, $lei) = @$arg;
-	if ($? == 0 && unlink("$mrr->{dst}/mirror.done")) {
+	my $f = "$mrr->{dst}/mirror.done";
+	if ($?) {
+		$lei->child_error($?);
+	} elsif (!unlink($f)) {
+		$lei->err("unlink($f): $!");
+	} else {
 		$lei->add_external_finish($mrr->{dst});
+		$lei->qerr("# mirrored $mrr->{src} => $mrr->{dst}");
 	}
 	$lei->dclose;
 }
@@ -262,8 +268,7 @@ sub do_mirror { # via wq_io_do
 		return start_clone_url($self) if $self->{src} =~ m!://!;
 		die "TODO: cloning local directories not supported, yet";
 	};
-	return $lei->fail($@) if $@;
-	$lei->qerr("# mirrored $self->{src} => $self->{dst}");
+	$lei->fail($@) if $@;
 }
 
 sub start {
diff --git a/t/lei-mirror.t b/t/lei-mirror.t
index 9769f31b..6039e568 100644
--- a/t/lei-mirror.t
+++ b/t/lei-mirror.t
@@ -41,6 +41,24 @@ test_lei({ tmpdir => $tmpdir }, sub {
 	ok(!-d "$t2-fail", 'destination not created on failure');
 	lei_ok('ls-external');
 	unlike($lei_out, qr!\Q$t2-fail\E!, 'not added to ls-external');
+
+	my %phail = (
+		HTTPS => 'https://public-inbox.org/' . 'phail',
+		ONION => 'http://ou63pmih66umazou.onion/' . 'phail,'
+	);
+	for my $t (qw(HTTPS ONION)) {
+	SKIP: {
+		my $k = "TEST_LEI_EXTERNAL_$t";
+		$ENV{$k} or skip "$k unset", 1;
+		my $url = $phail{$t};
+		my $dir = "phail-$t";
+		ok(!lei(qw(add-external -Lmedium --mirror),
+			$url, $dir), '--mirror non-existent v2');
+		is($? >> 8, 22, 'curl 404');
+		ok(!-d $dir, 'directory not created');
+		unlike($lei_err, qr/# mirrored/, 'no success message');
+	} # SKIP
+	} # for
 });
 
 ok($td->kill, 'killed -httpd');

  parent reply	other threads:[~2021-03-25  4:20 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-25  4:20 [PATCH 00/10] lei testing improvements Eric Wong
2021-03-25  4:20 ` [PATCH 01/10] test_common: cleanup inbox objects after use Eric Wong
2021-03-25  4:20 ` [PATCH 02/10] lei: janky $PATH2CFG garbage collection Eric Wong
2021-03-25  4:20 ` [PATCH 03/10] test_common: TEST_LEI_ERR_LOUD does not hide path names Eric Wong
2021-03-25  4:20 ` [PATCH 04/10] lei add-external: do not initialize writable store Eric Wong
2021-03-25  4:20 ` Eric Wong [this message]
2021-03-25  4:20 ` [PATCH 06/10] t/*: drop unnecessary v1-specific index calls Eric Wong
2021-03-25  4:20 ` [PATCH 07/10] tests: "check-run" uses persistent lei daemon Eric Wong
2021-03-25  4:20 ` [PATCH 08/10] lei import: force store, improve test diagnostics Eric Wong
2021-03-25  4:20 ` [PATCH 09/10] t/cmd_ipc: workaround signal handling raciness Eric Wong
2021-03-25  4:20 ` [PATCH 10/10] t/lei: add more diagnostics for failures 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=20210325042026.11270-6-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    --subject='Re: [PATCH 05/10] lei_mirror: don'\''t show success on failure' \
    /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

user/dev discussion of public-inbox itself

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 meta meta/ https://public-inbox.org/meta \
		meta@public-inbox.org
	public-inbox-index meta

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.mail.public-inbox.meta
	nntp://ie5yzdi7fg72h7s4sdcztq5evakq23rdt33mfyfcddc5u3ndnw24ogqd.onion/inbox.comp.mail.public-inbox.meta
	nntp://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git