-sub add_external_finish {
- my ($self, $location) = @_;
- my $cfg = $self->_lei_cfg(1);
- my $new_boost = $self->{opt}->{boost} // 0;
- 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);
-}
-
-sub lei_add_external {
- my ($self, $location) = @_;
- $self->_lei_store(1)->write_prepare($self);
- my $opt = $self->{opt};
- my $mirror = $opt->{mirror} // do {
- my @fail;
- for my $sw ($self->index_opt, $self->curl_opt,
- qw(c no-torsocks torsocks inbox-version)) {
- my ($f) = (split(/|/, $sw, 2))[0];
- next unless defined $opt->{$f};
- $f = length($f) == 1 ? "-$f" : "--$f";
- push @fail, $f;
- }
- if (scalar(@fail) == 1) {
- return $self->("@fail requires --mirror");
- } elsif (@fail) {
- my $last = pop @fail;
- my $fail = join(', ', @fail);
- return $self->("@fail and $last require --mirror");
- }
- undef;
- };
- my $new_boost = $opt->{boost} // 0;
- $location = ext_canonicalize($location);
- 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 {
- my ($self, @locations) = @_;
- my $cfg = $self->_lei_cfg(1);
- my $quiet = $self->{opt}->{quiet};
- my %seen;
- for my $loc (@locations) {
- my (@unset, @not_found);
- for my $l ($loc, ext_canonicalize($loc)) {
- next if $seen{$l}++;
- my $key = "external.$l.boost";
- delete($cfg->{$key});
- $self->_config('--unset', $key);
- if ($? == 0) {
- push @unset, $l;
- } elsif (($? >> 8) == 5) {
- push @not_found, $l;
- } else {
- $self->err("# --unset $key error");
- return $self->x_it($?);
- }
- }
- if (@unset) {
- next if $quiet;
- $self->err("# $_ gone") for @unset;
- } elsif (@not_found) {
- $self->err("# $_ not found") for @not_found;
- } # else { already exited
- }
-}
-
-sub _complete_url_common ($) {
- my ($argv) = @_;