unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH] extindex: --gc: use escape pathnames for SQL LIKE properly
@ 2021-04-24 10:23 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2021-04-24 10:23 UTC (permalink / raw)
  To: meta

This allows us to handle odd inboxes w/o a newsgroup configured
if they also make the strange choice of having backslashes in
their path name.  Also, ensure we use case-sensitive LIKE, since
case-insensitive FSes are not worth supporting.
---
 lib/PublicInbox/ExtSearchIdx.pm | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lib/PublicInbox/ExtSearchIdx.pm b/lib/PublicInbox/ExtSearchIdx.pm
index a17e7579..9d6b3b9d 100644
--- a/lib/PublicInbox/ExtSearchIdx.pm
+++ b/lib/PublicInbox/ExtSearchIdx.pm
@@ -336,9 +336,11 @@ sub eidx_gc {
 	$self->idx_init($opt); # acquire lock via V2Writable::_idx_init
 
 	my $dbh = $self->{oidx}->dbh;
+	$dbh->do('PRAGMA case_sensitive_like = ON'); # only place we use LIKE
 	my $x3_doc = $dbh->prepare('SELECT docid FROM xref3 WHERE ibx_id = ?');
 	my $ibx_ck = $dbh->prepare('SELECT ibx_id,eidx_key FROM inboxes');
-	my $lc_i = $dbh->prepare('SELECT key FROM eidx_meta WHERE key LIKE ?');
+	my $lc_i = $dbh->prepare(<<'');
+SELECT key FROM eidx_meta WHERE key LIKE ? ESCAPE ?
 
 	$ibx_ck->execute;
 	while (my ($ibx_id, $eidx_key) = $ibx_ck->fetchrow_array) {
@@ -354,8 +356,8 @@ DELETE FROM inboxes WHERE ibx_id = ?
 
 		# drop last_commit info
 		my $pat = $eidx_key;
-		$pat =~ s/([_%])/\\$1/g;
-		$lc_i->execute("lc-%:$pat//%");
+		$pat =~ s/([_%\\])/\\$1/g;
+		$lc_i->execute("lc-%:$pat//%", '\\');
 		while (my ($key) = $lc_i->fetchrow_array) {
 			next if $key !~ m!\Alc-v[1-9]+:\Q$eidx_key\E//!;
 			warn "I: removing $key\n";

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-04-24 10:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-24 10:23 [PATCH] extindex: --gc: use escape pathnames for SQL LIKE properly Eric Wong

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).