X-Git-Url: http://www.git.stargrave.org/?p=public-inbox.git;a=blobdiff_plain;f=lib%2FPublicInbox%2FLeiExternal.pm;h=6a5c2517b62db3cff539762b4d202d94894fe592;hp=accacf1a98d0ed15ed0ce079816380998a9912a6;hb=cfc2f64069e245a700b60113705be477857c51e5;hpb=d9bc0993fde567c9098020b8f79995e8ab3b4f0d diff --git a/lib/PublicInbox/LeiExternal.pm b/lib/PublicInbox/LeiExternal.pm index accacf1a..6a5c2517 100644 --- a/lib/PublicInbox/LeiExternal.pm +++ b/lib/PublicInbox/LeiExternal.pm @@ -88,19 +88,35 @@ sub get_externals { (); } -sub lei_add_external { +sub add_external_finish { my ($self, $location) = @_; my $cfg = $self->_lei_cfg(1); my $new_boost = $self->{opt}->{boost} // 0; - $location = ext_canonicalize($location); - if ($location !~ m!\Ahttps?://! && !-d $location) { - return $self->fail("$location not a directory"); - } my $key = "external.$location.boost"; my $cur_boost = $cfg->{$key}; return if defined($cur_boost) && $cur_boost == $new_boost; # idempotent $self->lei_config($key, $new_boost); - $self->_lei_store(1)->done; # just create the store +} + +sub lei_add_external { + my ($self, $location) = @_; + $self->_lei_store(1)->write_prepare($self); + my $new_boost = $self->{opt}->{boost} // 0; + $location = ext_canonicalize($location); + my $mirror = $self->{opt}->{mirror}; + if (defined($mirror) && -d $location) { + $self->fail(<<""); # TODO: did you mean "update-external?" +--mirror destination `$location' already exists + + } + if ($location !~ m!\Ahttps?://! && !-d $location) { + $mirror // return $self->fail("$location not a directory"); + $mirror = ext_canonicalize($mirror); + require PublicInbox::LeiMirror; + PublicInbox::LeiMirror->start($self, $mirror => $location); + } else { + add_external_finish($self, $location); + } } sub lei_forget_external {