our $LIVE; # pid => callback
+sub keep_going ($) {
+ $LIVE && (!$_[0]->{lei}->{child_error} ||
+ $_[0]->{lei}->{opt}->{'keep-going'});
+}
+
sub _wq_done_wait { # dwaitpid callback (via wq_eof)
my ($arg, $pid) = @_;
my ($mrr, $lei) = @$arg;
sub fgrp_update {
my ($fgrp) = @_;
+ return if !keep_going($fgrp);
my $srcfh = delete $fgrp->{srcfh} or return;
my $dstfh = delete $fgrp->{dstfh} or return;
seek($srcfh, SEEK_SET, 0) or die "seek(src): $!";
sub pack_refs {
my ($self, $git_dir) = @_;
do_reap($self);
+ return if !keep_going($self);
my $cmd = [ 'git', "--git-dir=$git_dir", qw(pack-refs --all --prune) ];
$self->{lei}->qerr("# @$cmd");
return if $self->{dry_run};
return if !$LIVE;
my $pid;
my $first = $fgrpv->[0] // die 'BUG: no fgrpv->[0]';
+ return if !keep_going($first);
pack_refs($first, $first->{-osdir}); # objstore refs always packed
for my $fgrp (@$fgrpv) {
my $rn = $fgrp->{-remote};
sub fp_done {
my ($self, $go_fetch) = @_;
+ return if !keep_going($self);
my $fh = delete $self->{-show_ref} // die 'BUG: no show-ref output';
seek($fh, SEEK_SET, 0) or die "seek(show_ref): $!";
$self->{-ent} // die 'BUG: no -ent';
sub resume_fetch {
my ($self, $uri, $fini) = @_;
+ return if !keep_going($self);
my $dst = $self->{cur_dst} // $self->{dst};
my @git = ('git', "--git-dir=$dst");
my $opt = { 2 => $self->{lei}->{2} };
sub fgrp_enqueue {
my ($self, $fgrp) = @_;
+ return if !keep_going($self);
my $opt = { 2 => $self->{lei}->{2} };
# --no-tags is required to avoid conflicts
my $u = $fgrp->{-uri} // die 'BUG: no {-uri}';
my ($self, $cmd) = @_;
my $cerr = $?;
$? = 0; # don't let it influence normal exit
- if ($cerr) {
- kill('TERM', keys %$LIVE);
- $self->{lei}->child_error($cerr, "@$cmd failed (\$?=$cerr)");
- }
+ $self->{lei}->child_error($cerr, "@$cmd failed (\$?=$cerr)") if $cerr;
}
sub v1_done { # called via OnDestroy
my ($self) = @_;
- return if $self->{dry_run} || !$LIVE;
+ return if $self->{dry_run} || !keep_going($self);
_write_inbox_config($self);
my $dst = $self->{cur_dst} // $self->{dst};
if (defined(my $o = $self->{-ent} ? $self->{-ent}->{owner} : undef)) {
sub v2_done { # called via OnDestroy
my ($self) = @_;
- return if $self->{dry_run} || !$LIVE;
+ return if $self->{dry_run} || !keep_going($self);
my $dst = $self->{cur_dst} // $self->{dst};
require PublicInbox::Lock;
my $lk = bless { lock_path => "$dst/inbox.lock" }, 'PublicInbox::Lock';
if (open(my $fh, '<', $fn)) {
decode_manifest($fh, $fn, $fn);
} elsif ($!{ENOENT}) { # non-fatal, we can just do it slowly
- warn "open($fn): $!\n";
+ warn "open($fn): $!\n" if !$self->{-initial_clone};
undef;
} else {
die "open($fn): $!\n";
# handle no-dependency repos, first
for (@$nodep) {
clone_v1($_, 1);
- return if $self->{lei}->{child_error};
+ return if !keep_going($self);
}
# resolve references, deepest, first:
while (scalar keys %$todo) {
my $y = delete $todo->{$x} // next; # already done
for (@$y) {
clone_v1($_, 1);
- return if $self->{lei}->{child_error};
+ return if !keep_going($self);
}
last; # restart %$todo iteration
}
my $path = $uri->path;
chop($path) eq '/' or die "BUG: $uri not canonicalized";
$uri->path($path . '/manifest.js.gz');
- my $ft = File::Temp->new(TEMPLATE => '.manifest-XXXX',
- UNLINK => 1, TMPDIR => 1, SUFFIX => '.tmp');
+ my $manifest = $self->{-manifest} // "$self->{dst}/manifest.js.gz";
+ my %opt = (UNLINK => 1, SUFFIX => '.tmp', TMPDIR => 1);
+ if (!$self->{dry_run} && $manifest =~ m!\A(.+?)/[^/]+\z! and -d $1) {
+ $opt{DIR} = $1; # allows fast rename(2) w/o EXDEV
+ delete $opt{TMPDIR};
+ }
+ my $ft = File::Temp->new(TEMPLATE => '.manifest-XXXX', %opt);
my $cmd = $curl->for_uri($lei, $uri, qw(-f -R -o), $ft->filename);
- my %opt = map { $_ => $lei->{$_} } (0..2);
+ %opt = map { $_ => $lei->{$_} } (0..2);
my $cerr = run_reap($lei, $cmd, \%opt);
if ($cerr) {
return try_scrape($self) if ($cerr >> 8) == 22; # 404 missing
E: `$self->{cur_dst}' must not contain newline
EOM
clone_v2_prep($self, \%v2_epochs, $m);
- return if $self->{lei}->{child_error};
+ return if !keep_going($self);
}
}
if (my $v1 = delete $multi->{v1}) {
}
delete local $lei->{opt}->{epoch} if defined($v2);
clone_all($self, $m);
- return if $self->{lei}->{child_error} || $self->{dry_run};
+ return if $self->{dry_run} || !keep_going($self);
# set by clone_v2_prep/-I/--exclude
dump_manifest($m => $ft) if delete $self->{-culled_manifest};
- ft_rename($ft, "$self->{dst}/manifest.js.gz", 0666);
+ ft_rename($ft, $manifest, 0666);
open my $x, '>', "$self->{dst}/mirror.done"; # for _wq_done_wait
}
my $lei = $self->{lei};
$self->{dry_run} = 1 if $lei->{opt}->{'dry-run'};
umask($lei->{client_umask}) if defined $lei->{client_umask};
+ $self->{-initial_clone} = 1 if !-d $self->{dst};
eval {
my $ic = $lei->{opt}->{'inbox-config'} //= 'always';
$ic =~ /\A(?:v1|v2|always|never)\z/s or die <<"";
my ($k) = (split(/\./, $default))[0];
my $v = $lei->{opt}->{$k} // next;
$v = $default if $v eq '';
- $v = "$self->{dst}/$v" if $v !~ m!\A/!;
+ $v = "$self->{dst}/$v" if $v !~ m!\A\.{0,2}/!;
$self->{"-$k"} = $v;
}
- local $LIVE;
+ local $LIVE = {};
my $iv = $lei->{opt}->{'inbox-version'} //
return start_clone_url($self);
return clone_v1($self) if $iv == 1;