]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei add-external: don't allow non-existent directories
authorEric Wong <e@80x24.org>
Sat, 23 Jan 2021 10:27:55 +0000 (10:27 +0000)
committerEric Wong <e@80x24.org>
Sun, 24 Jan 2021 10:08:16 +0000 (10:08 +0000)
At least not yet, though we may support mirroring via git.

lib/PublicInbox/LeiExternal.pm
t/lei.t

index e7693e09a7de67a427742590707926352e54aed0..bf07c41cf7215e01d02cc0e3b949f6958184a816 100644 (file)
@@ -58,6 +58,9 @@ sub lei_add_external {
        my $cfg = $self->_lei_cfg(1);
        my $new_boost = $self->{opt}->{boost} // 0;
        $location = _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
diff --git a/t/lei.t b/t/lei.t
index 6b45f5b7c34ec23e3483ee6b84a8fc6765198d83..60ca75c5da8084be83078b5679ac6176d3e0ed3f 100644 (file)
--- a/t/lei.t
+++ b/t/lei.t
@@ -193,6 +193,10 @@ my $test_external = sub {
        ok(!-e $config_file && !-e $store_dir,
                'nothing created by ls-external');
 
+       ok(!$lei->('add-external', "$home/nonexistent"),
+               "fails on non-existent dir");
+       $lei->('ls-external');
+       is($out.$err, '', 'ls-external still has no output');
        my $cfg = PublicInbox::Config->new;
        $cfg->each_inbox(sub {
                my ($ibx) = @_;