]> Sergey Matveev's repositories - public-inbox.git/commitdiff
extindex: --gc: use escape pathnames for SQL LIKE properly
authorEric Wong <e@80x24.org>
Sat, 24 Apr 2021 10:23:30 +0000 (10:23 +0000)
committerEric Wong <e@80x24.org>
Sat, 24 Apr 2021 20:10:04 +0000 (16:10 -0400)
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

index a17e7579c7772ab9febc9bfcab025d81f5720ed4..9d6b3b9dc99bee09a318fc609373c7dd90f49137 100644 (file)
@@ -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";