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

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