* [PATCH 2/3] lei_saved_search: canonicalized relative save paths
2021-08-11 11:26 7% [PATCH 0/3] lei pathname canonicalization fixes Eric Wong
@ 2021-08-11 11:26 7% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2021-08-11 11:26 UTC (permalink / raw)
To: meta
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;
^ permalink raw reply related [relevance 7%]
* [PATCH 0/3] lei pathname canonicalization fixes
@ 2021-08-11 11:26 7% Eric Wong
2021-08-11 11:26 7% ` [PATCH 2/3] lei_saved_search: canonicalized relative save paths Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2021-08-11 11:26 UTC (permalink / raw)
To: meta
Pathnames with "x/../y" components weren't being canonicalized
properly after creation, and some of it was being put into the
lei_mail_sync.sqlite3 DB and configs for saved searches.
This will become more important as we start using inotify more
to track keyword changes on messages.
Eric Wong (3):
treewide: use *nix-specific dirname regexps
lei_saved_search: canonicalized relative save paths
lei: attempt to canonicalize away "/../" pathnames
lib/PublicInbox/IMAPTracker.pm | 4 ++--
lib/PublicInbox/LEI.pm | 16 +++++++++++-----
lib/PublicInbox/LeiALE.pm | 8 ++++----
lib/PublicInbox/LeiBlob.pm | 4 ++--
lib/PublicInbox/LeiInit.pm | 3 +--
lib/PublicInbox/LeiLcat.pm | 2 +-
lib/PublicInbox/LeiOverview.pm | 2 +-
lib/PublicInbox/LeiQuery.pm | 2 +-
lib/PublicInbox/LeiRediff.pm | 2 +-
lib/PublicInbox/LeiSavedSearch.pm | 9 ++++++++-
lib/PublicInbox/LeiUp.pm | 2 +-
lib/PublicInbox/OverIdx.pm | 4 ++--
lib/PublicInbox/Xapcmd.pm | 5 ++---
script/public-inbox-init | 3 +--
t/init.t | 1 -
t/lei-q-save.t | 9 +++++++++
t/lei_xsearch.t | 8 +++++---
17 files changed, 52 insertions(+), 32 deletions(-)
^ permalink raw reply [relevance 7%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2021-08-11 11:26 7% [PATCH 0/3] lei pathname canonicalization fixes Eric Wong
2021-08-11 11:26 7% ` [PATCH 2/3] lei_saved_search: canonicalized relative save paths Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).