[yum-git] Branch 'yum-3_2_X' - 2 commits - yum/misc.py yum/sqlitesack.py

James Antill james at linux.duke.edu
Tue Aug 19 17:26:30 UTC 2008


 yum/misc.py       |    2 +-
 yum/sqlitesack.py |   27 ++++++++++++++++++++-------
 2 files changed, 21 insertions(+), 8 deletions(-)

New commits:
commit cceaebd9957495300693a5824c224136da536493
Author: James Antill <james at and.org>
Date:   Tue Aug 19 13:24:12 2008 -0400

     Fix LIKE SQL queries with [] in the input.
      Eg. yum list yum[!a]3.2.17[!a]2.fc9
      Needs to match yum-3.2.17-2.fc9
    
     Yes, it's a crazy corner case ... yes, it's a simplish fix to dtwt.

diff --git a/yum/sqlitesack.py b/yum/sqlitesack.py
index 8813005..ba64481 100644
--- a/yum/sqlitesack.py
+++ b/yum/sqlitesack.py
@@ -482,6 +482,21 @@ class YumSqlitePackageSack(yumRepo.YumPackageSack):
             pattern = pattern.replace("_", "!_")
         return (pattern, esc)
 
+    def _sql_esc_glob(self, patterns):
+        """ Converts patterns to SQL LIKE format, if required (or gives up if
+            not possible). """
+        ret = []
+        for pattern in patterns:
+            if '[' in pattern: # LIKE only has % and _, so [abc] can't be done.
+                return []      # So Load everything
+
+            # Convert to SQL LIKE format
+            (pattern, esc) = self._sql_esc(pattern)
+            pattern = pattern.replace("*", "%")
+            pattern = pattern.replace("?", "_")
+            ret.append((pattern, esc))
+        return ret
+
     def _skip_all(self):
         """ Are we going to skip every package in all our repos? """
         skip_all = True
@@ -1115,15 +1130,13 @@ class YumSqlitePackageSack(yumRepo.YumPackageSack):
 
                 pat_sqls = []
                 pat_data = []
-                for pattern in patterns:
-                    done = False
+                if ignore_case:
+                    patterns = self._sql_esc_glob(patterns)
+                else:
+                    patterns = map(lambda x: (x, ''), patterns)
+                for (pattern, esc) in patterns:
                     for field in fields:
                         if ignore_case:
-                            if not done:
-                                done = True
-                                (pattern, esc) = self._sql_esc(pattern)
-                                pattern = pattern.replace("*", "%")
-                                pattern = pattern.replace("?", "_")
                             pat_sqls.append("%s LIKE ?%s" % (field, esc))
                         else:
                             pat_sqls.append("%s GLOB ?" % field)
commit 76a270bbc1f920bb3a47212803b4f2e123ca0995
Author: James Antill <james at and.org>
Date:   Tue Aug 19 13:15:10 2008 -0400

    Add [] to set of wildcards

diff --git a/yum/misc.py b/yum/misc.py
index 5e58ebd..b9cc387 100644
--- a/yum/misc.py
+++ b/yum/misc.py
@@ -92,7 +92,7 @@ def re_full_search_needed(s):
     """ Tests if a string needs a full nevra match, instead of just name. """
     global _re_compiled_full_match
     if _re_compiled_full_match is None:
-        one   = re.compile('.*[-\*\?].*.$') # Any wildcard or - seperator
+        one   = re.compile('.*[-\*\?\[\]].*.$') # Any wildcard or - seperator
         two   = re.compile('^[0-9]')        # Any epoch, for envra
         _re_compiled_full_match = (one, two)
     for rec in _re_compiled_full_match:



More information about the Yum-cvs-commits mailing list