diff options
author | Eric Wong <e@80x24.org> | 2021-02-06 12:18:40 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-02-07 03:34:32 +0000 |
commit | cfc2f64069e245a700b60113705be477857c51e5 (patch) | |
tree | bfcf20bdd19357bbd6399798b351e9a5bbe9c97e /lib/PublicInbox/LeiExternal.pm | |
parent | d9bc0993fde567c9098020b8f79995e8ab3b4f0d (diff) | |
download | public-inbox-cfc2f64069e245a700b60113705be477857c51e5.tar.gz |
This can be useful for users who want to clone and mirror an existing public-inbox. This doesn't have update support, yet, so users will need to run "git fetch && public-inbox-index" for now.
Diffstat (limited to 'lib/PublicInbox/LeiExternal.pm')
-rw-r--r-- | lib/PublicInbox/LeiExternal.pm | 28 |
1 files changed, 22 insertions, 6 deletions
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 { |