Blame SOURCES/0028-Add-obsoletes-to-filtering-for-advisory-candidates.patch

931180
From fa6da3b29705b99de69a653e869af258ac302ab6 Mon Sep 17 00:00:00 2001
931180
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
931180
Date: Tue, 5 Jul 2022 09:02:22 +0200
931180
Subject: [PATCH] Add obsoletes to filtering for advisory candidates
931180
931180
Patch https://github.com/rpm-software-management/libdnf/pull/1526
931180
introduced a regression where we no longer do a security upgrade if a
931180
package A is installed and package B obsoletes A and B is available in two
931180
versions while there is an advisory for the second version.
931180
931180
Test: https://github.com/rpm-software-management/ci-dnf-stack/pull/1130
931180
---
931180
 libdnf/sack/query.cpp | 32 ++++++++++++++++++++++++++++----
931180
 1 file changed, 28 insertions(+), 4 deletions(-)
931180
931180
diff --git a/libdnf/sack/query.cpp b/libdnf/sack/query.cpp
931180
index 03d39659..5355f9f7 100644
931180
--- a/libdnf/sack/query.cpp
931180
+++ b/libdnf/sack/query.cpp
931180
@@ -1878,6 +1878,13 @@ Query::Impl::filterAdvisory(const Filter & f, Map *m, int keyname)
931180
         std::vector<Solvable *> installed_solvables;
931180
 
931180
         if (cmp_type & HY_UPGRADE) {
931180
+            // When doing HY_UPGRADE consider only candidate pkgs that have matching Name and Arch with:
931180
+            // * some already installed pkg (in other words: some other version of the pkg is already installed)
931180
+            // or
931180
+            // * with pkg that obsoletes some already installed (or to be installed in this transaction) pkg
931180
+            // Otherwise a pkg with different Arch than installed can end up in upgrade set which is wrong.
931180
+            // It can result in dependency issues, reported as: RhBug:2088149.
931180
+
931180
             Query installed(sack, ExcludeFlags::IGNORE_EXCLUDES);
931180
             installed.installed();
931180
             installed.addFilter(HY_PKG_LATEST_PER_ARCH, HY_EQ, 1);
931180
@@ -1887,13 +1894,30 @@ Query::Impl::filterAdvisory(const Filter & f, Map *m, int keyname)
931180
                 installed_solvables.push_back(pool_id2solvable(pool, installed_id));
931180
             }
931180
             std::sort(installed_solvables.begin(), installed_solvables.end(), NameArchSolvableComparator);
931180
+
931180
+            Query obsoletes(sack, ExcludeFlags::IGNORE_EXCLUDES);
931180
+            obsoletes.addFilter(HY_PKG, HY_EQ, resultPset);
931180
+            obsoletes.available();
931180
+
931180
+            Query possibly_obsoleted(sack, ExcludeFlags::IGNORE_EXCLUDES);
931180
+            possibly_obsoleted.addFilter(HY_PKG, HY_EQ, resultPset);
931180
+            possibly_obsoleted.addFilter(HY_PKG_UPGRADES, HY_EQ, 1);
931180
+            possibly_obsoleted.queryUnion(installed);
931180
+            possibly_obsoleted.apply();
931180
+
931180
+            obsoletes.addFilter(HY_PKG_OBSOLETES, HY_EQ, possibly_obsoleted.runSet());
931180
+            obsoletes.apply();
931180
+            Id obsoleted_id = -1;
931180
+            // Add to candidates resultPset pkgs that obsolete some installed (or to be installed in this transaction) pkg
931180
+            while ((obsoleted_id = obsoletes.pImpl->result->next(obsoleted_id)) != -1) {
931180
+                Solvable * s = pool_id2solvable(pool, obsoleted_id);
931180
+                candidates.push_back(s);
931180
+            }
931180
+
931180
             Id id = -1;
931180
+            // Add to candidates resultPset pkgs that match name and arch with some already installed pkg
931180
             while ((id = resultPset->next(id)) != -1) {
931180
                 Solvable * s = pool_id2solvable(pool, id);
931180
-                // When doing HY_UPGRADE consider only candidate pkgs that have matching Name and Arch
931180
-                // with some already installed pkg (in other words: some other version of the pkg is already installed).
931180
-                // Otherwise a pkg with different Arch than installed can end up in upgrade set which is wrong.
931180
-                // It can result in dependency issues, reported as: RhBug:2088149.
931180
                 auto low = std::lower_bound(installed_solvables.begin(), installed_solvables.end(), s, NameArchSolvableComparator);
931180
                 if (low != installed_solvables.end() && s->name == (*low)->name && s->arch == (*low)->arch) {
931180
                     candidates.push_back(s);
931180
-- 
931180
2.37.1
931180