Blame SOURCES/BZ-1306142-allow-older-installonly-deps.patch

5e9bef
commit afac6a760b97b7dd71c06c00a4716d3212f6884c
5e9bef
Author: Masahiro Matsuya <mmatsuya@redhat.com>
5e9bef
Date:   Wed Apr 20 10:16:10 2016 +0200
5e9bef
5e9bef
    Cope with older installonly packages from deps. BZ 1306142
5e9bef
    
5e9bef
    We have been doing this with explicitly installed packages but not for
5e9bef
    their dependencies, so let's do it after depsolving again to cover those
5e9bef
    too.
5e9bef
5e9bef
diff --git a/test/operationstests.py b/test/operationstests.py
5e9bef
index 5a50439..bd999e6 100644
5e9bef
--- a/test/operationstests.py
5e9bef
+++ b/test/operationstests.py
5e9bef
@@ -1,3 +1,4 @@
5e9bef
+import rpm
5e9bef
 from testbase import *
5e9bef
 import simpleobsoletestests
5e9bef
 
5e9bef
@@ -142,6 +143,17 @@ class KernelTests(OperationsTests):
5e9bef
         res, msg = self.runOperation(['install','kernel-2.6.23.8'], p.inst, p.avail)
5e9bef
         self.assertResult(p.inst)
5e9bef
 
5e9bef
+    def testRequireOlderKernel(self):
5e9bef
+        p = self.pkgs
5e9bef
+
5e9bef
+        foo = FakePackage('foo', '1.0', '1', arch='i686')
5e9bef
+        foo.addRequires('kernel', 'EQ', (None, '2.6.23.5', '1'))
5e9bef
+        navail = [foo, FakePackage('kernel', '2.6.23.5', '1',arch='i686')]
5e9bef
+
5e9bef
+        res, msg = self.runOperation(['install', 'foo'], p.inst, navail)
5e9bef
+        self.assertResult(p.inst + navail)
5e9bef
+        self.assertEquals(self.tsInfo.probFilterFlags, [rpm.RPMPROB_FILTER_OLDPACKAGE])
5e9bef
+
5e9bef
 class MultiLibTests(OperationsTests):
5e9bef
 
5e9bef
     @staticmethod
5e9bef
diff --git a/yum/__init__.py b/yum/__init__.py
5e9bef
index acaa973..c896fff 100644
5e9bef
--- a/yum/__init__.py
5e9bef
+++ b/yum/__init__.py
5e9bef
@@ -1356,6 +1356,17 @@ much more problems).
5e9bef
 
5e9bef
         if rescode == 2:
5e9bef
             self.save_ts(auto=True)
5e9bef
+
5e9bef
+        # Make sure we don't fail in rpm if we're installing a package that is
5e9bef
+        # allowed multiple installs but has a newer version already installed.
5e9bef
+        # Note that we already have a similar check in install(), but here we
5e9bef
+        # do it to cover anything that was pulled in as a dependency.
5e9bef
+        if rpm.RPMPROB_FILTER_OLDPACKAGE not in self.tsInfo.probFilterFlags:
5e9bef
+            for m in self.tsInfo.getMembers():
5e9bef
+                if m.ts_state == 'i' and self.allowedMultipleInstalls(m.po):
5e9bef
+                    if self._enable_oldpackage_flag(m.po):
5e9bef
+                        break
5e9bef
+
5e9bef
         self.verbose_logger.debug('Depsolve time: %0.3f' % (time.time() - ds_st))
5e9bef
         return rescode, restring
5e9bef
 
5e9bef
@@ -4674,6 +4685,14 @@ much more problems).
5e9bef
             if flag not in self.tsInfo.probFilterFlags:
5e9bef
                 self.tsInfo.probFilterFlags.append(flag)
5e9bef
 
5e9bef
+    def _enable_oldpackage_flag(self, po):
5e9bef
+        """Add RPMPROB_FILTER_OLDPACKAGE if the package requires it."""
5e9bef
+        for ipkg in self.rpmdb.searchNevra(name=po.name):
5e9bef
+            if ipkg.verGT(po) and not canCoinstall(ipkg.arch, po.arch):
5e9bef
+                self._add_prob_flags(rpm.RPMPROB_FILTER_OLDPACKAGE)
5e9bef
+                return True
5e9bef
+        return False
5e9bef
+
5e9bef
     def _install_is_upgrade(self, po, ipkgs):
5e9bef
         """ See if po is an upgradeable version of an installed pkg.
5e9bef
         Non-compat. arch differences mean no. """
5e9bef
@@ -4969,10 +4988,7 @@ much more problems).
5e9bef
                     # and a remove, which also tries to remove the old version.
5e9bef
                     self.tsInfo.remove(ipkg.pkgtup)
5e9bef
                     break
5e9bef
-            for ipkg in self.rpmdb.searchNevra(name=po.name):
5e9bef
-                if ipkg.verGT(po) and not canCoinstall(ipkg.arch, po.arch):
5e9bef
-                    self._add_prob_flags(rpm.RPMPROB_FILTER_OLDPACKAGE)
5e9bef
-                    break
5e9bef
+            self._enable_oldpackage_flag(po)
5e9bef
             
5e9bef
             # it doesn't obsolete anything. If it does, mark that in the tsInfo, too
5e9bef
             obs_pkgs = list(self._find_obsoletees_direct(po))