Blame SOURCES/BZ-1352585-detect-installed-provide.patch

d2a170
commit ed2a41fe646a1dcfc4f216f8babf25f93fde40e3
d2a170
Author: Michal Domonkos <mdomonko@redhat.com>
d2a170
Date:   Fri Feb 3 18:24:37 2017 +0100
d2a170
d2a170
    Detect installed virtual provide in install(). BZ 1352585
d2a170
    
d2a170
    Normally, when the user tries to install something that's already
d2a170
    installed, we exit gracefully with 0.  However, that's not the case if
d2a170
    what we're looking for is a provide that, despite being installed, is
d2a170
    not available in any of the enabled repos, in which case we error out.
d2a170
    This commit makes sure we exit gracefully in that case too.
d2a170
    
d2a170
    The old code path for "yum install foo" looks like this:
d2a170
    
d2a170
    1) Look for foo in pkgSack
d2a170
    2) If no success, look for a package in pkgSack providing foo
d2a170
    3) If no success, look for foo in rpmdb
d2a170
    4) If no success, error out with "No package foo available." and exit
d2a170
       code 1
d2a170
    
d2a170
    What we're adding with this commit is the following in between 3 and 4:
d2a170
    
d2a170
    - If no success, look for a package in rpmdb providing foo
d2a170
    
d2a170
    Note that we only search for the provide in pkgSack if the kwarg
d2a170
    'pattern' is set, so let's adhere to this with the newly added rpmdb
d2a170
    search too.
d2a170
d2a170
diff --git a/yum/__init__.py b/yum/__init__.py
d2a170
index 9780d96..451b2b8 100644
d2a170
--- a/yum/__init__.py
d2a170
+++ b/yum/__init__.py
d2a170
@@ -4910,8 +4910,14 @@ much more problems).
d2a170
             # Do we still want to return errors here?
d2a170
             # We don't in the cases below, so I didn't here...
d2a170
             if 'pattern' in kwargs:
d2a170
-                pkgs = self.rpmdb.returnPackages(patterns=[kwargs['pattern']],
d2a170
+                arg = kwargs['pattern']
d2a170
+                pkgs = self.rpmdb.returnPackages(patterns=[arg],
d2a170
                                                  ignore_case=False)
d2a170
+                if not pkgs:
d2a170
+                    self.verbose_logger.debug(
d2a170
+                        _('Checking for installed virtual provide or file-provide for %s'),
d2a170
+                        arg)
d2a170
+                    pkgs = self.returnInstalledPackagesByDep(arg)
d2a170
             if 'name' in kwargs:
d2a170
                 pkgs = self.rpmdb.searchNevra(name=kwargs['name'])
d2a170
             if 'pkgtup' in kwargs: