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-ASN: 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 340951F8C8 for ; Wed, 11 Aug 2021 11:26:19 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 2/3] lei_saved_search: canonicalized relative save paths Date: Wed, 11 Aug 2021 11:26:17 +0000 Message-Id: <20210811112618.24084-3-e@80x24.org> In-Reply-To: <20210811112618.24084-1-e@80x24.org> References: <20210811112618.24084-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Storing relative paths with '..' in them can be expensive to resolve when running 'lei up', so prefer storing canonicalized absolute paths. We only do this for paths with '..' in them, though, since this can lose symlink info. --- lib/PublicInbox/LeiSavedSearch.pm | 9 ++++++++- t/lei-q-save.t | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/PublicInbox/LeiSavedSearch.pm b/lib/PublicInbox/LeiSavedSearch.pm index cfbf68c3..2a0e9321 100644 --- a/lib/PublicInbox/LeiSavedSearch.pm +++ b/lib/PublicInbox/LeiSavedSearch.pm @@ -115,9 +115,16 @@ sub up { # updating existing saved search via "lei up" sub new { # new saved search "lei q --save" my ($cls, $lei) = @_; my $self = bless { ale => $lei->ale }, $cls; + require File::Path; my $dst = $lei->{ovv}->{dst}; + + # canonicalize away relative paths into the config + if ($lei->{ovv}->{fmt} eq 'maildir' && + $dst =~ m!(?:/*|\A)\.\.(?:/*|\z)! && !-d $dst) { + File::Path::make_path($dst); + $lei->{ovv}->{dst} = $dst = $lei->abs_path($dst); + } my $dir = lss_dir_for($lei, \$dst); - require File::Path; File::Path::make_path($dir); # raises on error $self->{-cfg} = {}; my $f = $self->{'-f'} = "$dir/lei.saved-search"; diff --git a/t/lei-q-save.t b/t/lei-q-save.t index b1ca4e92..eada2dd4 100644 --- a/t/lei-q-save.t +++ b/t/lei-q-save.t @@ -202,5 +202,14 @@ test_lei(sub { lei_ok([qw(edit-search), $v2s], { VISUAL => 'cat', EDITOR => 'cat' }); like($lei_out, qr/^\[lei/sm, 'edit-search can cat'); + + lei_ok('-C', "$home/v2s", + qw(q -q --save -o ../s m:testmessage@example.com)); + lei_ok qw(ls-search); + unlike $lei_out, qr{/\.\./s$}sm, 'relative path not in ls-search'; + like $lei_out, qr{^\Q$home\E/s$}sm, + 'absolute path appears in ls-search'; + lei_ok qw(up ../s -C), "$home/v2s", \'relative lei up'; + lei_ok qw(up), "$home/s", \'absolute lei up'; }); done_testing;