From: Eric Wong Date: Wed, 15 Sep 2021 17:43:41 +0000 (+0000) Subject: lei_saved_search: fix prefix for IMAP folders w/ slash X-Git-Tag: v1.7.0~375 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=ae6cd61cf7cb9988d6e9178dbdeebfb6109e74da;p=public-inbox.git lei_saved_search: fix prefix for IMAP folders w/ slash We failed to account for IMAP mailboxes containing `/' characters when creating saved search files for them. Reported-by: Konstantin Ryabitsev Link: https://public-inbox.org/meta/20210915123347.knr4qpaei73tjc5q@meerkat.local/ --- diff --git a/lib/PublicInbox/LeiSavedSearch.pm b/lib/PublicInbox/LeiSavedSearch.pm index 8ceaaf01..96ff816e 100644 --- a/lib/PublicInbox/LeiSavedSearch.pm +++ b/lib/PublicInbox/LeiSavedSearch.pm @@ -39,21 +39,21 @@ sub cfg_dump ($$) { sub lss_dir_for ($$;$) { my ($lei, $dstref, $on_fs) = @_; - my @n; + my $pfx; if ($$dstref =~ m,\Aimaps?://,i) { # already canonicalized require PublicInbox::URIimap; my $uri = PublicInbox::URIimap->new($$dstref)->canonical; $$dstref = $$uri; - @n = ($uri->mailbox); + $pfx = $uri->mailbox; } else { # can't use Cwd::abs_path since dirname($$dstref) may not exist $$dstref = $lei->rel2abs($$dstref); $$dstref =~ tr!/!/!s; - @n = ($$dstref =~ m{([^/]+)/*\z}); # basename + $pfx = $$dstref; } - push @n, sha256_hex($$dstref); + ($pfx) = ($pfx =~ m{([^/]+)/*\z}); # basename my $lss_dir = $lei->share_path . '/saved-searches/'; - my $d = $lss_dir . join('-', @n); + my $d = "$lss_dir$pfx-".sha256_hex($$dstref); # fall-back to looking up by st_ino + st_dev in case we're in # a symlinked or bind-mounted path @@ -61,7 +61,7 @@ sub lss_dir_for ($$;$) { my @cur = stat(_); my $want = pack('dd', @cur[1,0]); # st_ino + st_dev my ($c, $o, @st); - for my $g ("$n[0]-*", '*') { + for my $g ("$pfx-*", '*') { my @maybe = glob("$lss_dir$g/lei.saved-search"); for my $f (@maybe) { $c = cfg_dump($lei, $f) // next;