]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei_mirror: don't show success on failure
authorEric Wong <e@80x24.org>
Thu, 25 Mar 2021 04:20:21 +0000 (06:20 +0200)
committerEric Wong <e@80x24.org>
Thu, 25 Mar 2021 17:58:59 +0000 (17:58 +0000)
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
t/lei-mirror.t

index d68cd6c1615cea67c4577d76e60588a83d288eb4..c83386c61ff4717b9f90b63607818d859639a8e2 100644 (file)
@@ -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 {
index 9769f31bdc3fe1efd8d2566fe5deefd0e5d9b163..6039e568224f3d51d65656035898f5d374724a48 100644 (file)
@@ -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');