[Yum-devel] [PATCH] Fix "yum install '[x/y]bin/zsh'". Also makes the code neater.
James Antill
james at and.org
Tue Sep 22 15:31:40 UTC 2009
Because we need matching [], we can't just do a re_glob() of the first
char anymore. So we careate a new re_filename() function. This is also
clever enough that it doesn't match "[xy]bin/zsh", however negated
character classes and character class ranges are on their own (don't do
that).
Also add some doc comments to the re_* functions.
---
yum/__init__.py | 5 +----
yum/depsolve.py | 2 +-
yum/misc.py | 14 +++++++++++++-
yum/sqlitesack.py | 2 +-
4 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/yum/__init__.py b/yum/__init__.py
index 90cdf8d..244f83f 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -2041,10 +2041,7 @@ class YumBase(depsolve.Depsolve):
canBeFile = True
else:
isglob = True
- if arg[0] != '/' and not misc.re_glob(arg[0]):
- canBeFile = False
- else:
- canBeFile = True
+ canBeFile = misc.re_filename(arg)
if not isglob:
usedDepString = True
diff --git a/yum/depsolve.py b/yum/depsolve.py
index 89adfda..c5baacb 100644
--- a/yum/depsolve.py
+++ b/yum/depsolve.py
@@ -174,7 +174,7 @@ class Depsolve(object):
for po in pkgs:
self.verbose_logger.log(logginglevels.DEBUG_2,
_('Potential match for %s from %s'), name, po)
- if (name[0] == '/' or misc.re_glob(name[0])) and r_v is None:
+ if misc.re_filename(name) and r_v is None:
# file dep add all matches to the defSack
defSack.addPackage(po)
continue
diff --git a/yum/misc.py b/yum/misc.py
index a092b65..17e5ef6 100644
--- a/yum/misc.py
+++ b/yum/misc.py
@@ -76,14 +76,25 @@ def unshare_data():
_re_compiled_glob_match = None
def re_glob(s):
""" Tests if a string is a shell wildcard. """
- # re.match('.*[\*\?\[\]].*', name)
global _re_compiled_glob_match
if _re_compiled_glob_match is None:
_re_compiled_glob_match = re.compile('.*([*?]|\[.+\])')
return _re_compiled_glob_match.match(s)
+_re_compiled_filename_match = None
+def re_filename(s):
+ """ Tests if a string could be a filename. We still get negated character
+ classes wrong (are they supported), and ranges in character classes. """
+ global _re_compiled_filename_match
+ if _re_compiled_filename_match is None:
+ _re_compiled_filename_match = re.compile('^(/|[*?]|\[[^]]*/[^]]*\])')
+ return _re_compiled_filename_match.match(s)
+
_re_compiled_pri_fnames_match = None
def re_primary_filename(filename):
+ """ Tests if a filename string, can be matched against just primary.
+ Note that this can produce false negatives (but not false
+ positives). """
global _re_compiled_pri_fnames_match
if _re_compiled_pri_fnames_match is None:
one = re.compile('.*bin\/.*')
@@ -97,6 +108,7 @@ def re_primary_filename(filename):
_re_compiled_pri_dnames_match = None
def re_primary_dirname(dirname):
+ """ Tests if a dirname string, can be matched against just primary. """
global _re_compiled_pri_dnames_match
if _re_compiled_pri_dnames_match is None:
one = re.compile('.*bin\/.*')
diff --git a/yum/sqlitesack.py b/yum/sqlitesack.py
index 3dd93a5..9bfcd93 100644
--- a/yum/sqlitesack.py
+++ b/yum/sqlitesack.py
@@ -1281,7 +1281,7 @@ class YumSqlitePackageSack(yumRepo.YumPackageSack):
# If it's not a provides or a filename, we are done
if prcotype != "provides":
return results
- if name[0] != '/' and (not glob or not misc.re_glob(name[0])):
+ if not misc.re_filename(name):
return results
# If it is a filename, search the primary.xml file info
--
1.6.2.5
More information about the Yum-devel
mailing list