]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LeiMirror.pm
lei: use standard warn() in more places
[public-inbox.git] / lib / PublicInbox / LeiMirror.pm
index 5cfa6fea851c9d11b6979228e9e950c49adef69d..ec41bec6f16b51547a9ab56bdea4279b6635e3a9 100644 (file)
@@ -20,7 +20,7 @@ sub _wq_done_wait { # dwaitpid callback (via wq_eof)
        if ($?) {
                $lei->child_error($?);
        } elsif (!unlink($f)) {
-               $lei->err("unlink($f): $!") unless $!{ENOENT};
+               warn("unlink($f): $!\n") unless $!{ENOENT};
        } else {
                if ($lei->{cmd} ne 'public-inbox-clone') {
                        $lei->lazy_cb('add-external', '_finish_'
@@ -96,15 +96,15 @@ sub _get_txt { # non-fatal
        my $path = $uri->path;
        chop($path) eq '/' or die "BUG: $uri not canonicalized";
        $uri->path("$path/$endpoint");
-       my $cmd = $self->{curl}->for_uri($lei, $uri, '--compressed');
-       my $ce = "$self->{dst}/$file";
-       my $ft = File::Temp->new(TEMPLATE => "$file-XXXX",
-                               UNLINK => 1, DIR => $self->{dst});
-       my $opt = { 0 => $lei->{0}, 1 => $ft, 2 => $lei->{2} };
+       my $ft = File::Temp->new(TEMPLATE => "$file-XXXX", DIR => $self->{dst});
+       my $f = $ft->filename;
+       my $opt = { 0 => $lei->{0}, 1 => $lei->{1}, 2 => $lei->{2} };
+       my $cmd = $self->{curl}->for_uri($lei, $uri,
+                                       qw(--compressed -R -o), $f);
        my $cerr = run_reap($lei, $cmd, $opt);
        return "$uri missing" if ($cerr >> 8) == 22;
        return "# @$cmd failed (non-fatal)" if $cerr;
-       my $f = $ft->filename;
+       my $ce = "$self->{dst}/$file";
        rename($f, $ce) or return "rename($f, $ce): $! (non-fatal)";
        $ft->unlink_on_destroy(0);
        undef; # success
@@ -120,8 +120,9 @@ sub _try_config {
                -d $dst or die "mkpath($dst): $!\n";
        }
        my $err = _get_txt($self, qw(_/text/config/raw inbox.config.example));
-       return $self->{lei}->err($err) if $err;
+       return warn($err, "\n") if $err;
        my $f = "$self->{dst}/inbox.config.example";
+       chmod((stat($f))[2] & 0444, $f) or die "chmod(a-w, $f): $!";
        my $cfg = PublicInbox::Config->git_config_dump($f, $self->{lei}->{2});
        my $ibx = $self->{ibx} = {};
        for my $sec (grep(/\Apublicinbox\./, @{$cfg->{-section_order}})) {
@@ -150,7 +151,7 @@ sub index_cloned_inbox {
        my ($self, $iv) = @_;
        my $lei = $self->{lei};
        my $err = _get_txt($self, qw(description description));
-       $lei->err($err) if $err; # non fatal
+       warn($err, "\n") if $err; # non fatal
        eval { set_description($self) };
        warn $@ if $@;
 
@@ -379,7 +380,7 @@ sub try_manifest {
        my ($path_pfx, $v1_path, @v2_epochs) = deduce_epochs($m, $path);
        if (@v2_epochs) {
                # It may be possible to have v1 + v2 in parallel someday:
-               $lei->err(<<EOM) if defined $v1_path;
+               warn(<<EOM) if defined $v1_path;
 # `$v1_path' appears to be a v1 inbox while v2 epochs exist:
 # @v2_epochs
 # ignoring $v1_path (use --inbox-version=1 to force v1 instead)