From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id AF4801FB07 for ; Sat, 23 Jan 2021 10:27:56 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 10/10] lei add-external: don't allow non-existent directories Date: Sat, 23 Jan 2021 10:27:55 +0000 Message-Id: <20210123102755.425-11-e@80x24.org> In-Reply-To: <20210123102755.425-1-e@80x24.org> References: <20210123102755.425-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: At least not yet, though we may support mirroring via git. --- lib/PublicInbox/LeiExternal.pm | 3 +++ t/lei.t | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/lib/PublicInbox/LeiExternal.pm b/lib/PublicInbox/LeiExternal.pm index e7693e09..bf07c41c 100644 --- a/lib/PublicInbox/LeiExternal.pm +++ b/lib/PublicInbox/LeiExternal.pm @@ -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 6b45f5b7..60ca75c5 100644 --- 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) = @_;