Blame SOURCES/0001-Allow-change-of-arch-during-security-updates-with-no.patch

480e54
From 2834747bff215c6f8da4eef2820c29bc05e172e1 Mon Sep 17 00:00:00 2001
480e54
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
480e54
Date: Wed, 7 Sep 2022 09:07:04 +0200
480e54
Subject: [PATCH] Allow change of arch during security updates with noarch
480e54
 (RhBug:2124483)
480e54
480e54
This matches upgrade behaviour where upgrading from/to noarch is a
480e54
special case and architecture change of a package is allowed
480e54
automatically.
480e54
480e54
= changelog =
480e54
msg: Allow change of architecture for packages during security updates with noarch involved
480e54
type: security
480e54
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2124483
480e54
---
480e54
 libdnf/sack/query.cpp | 34 ++++++++++++++++++++++++----------
480e54
 1 file changed, 24 insertions(+), 10 deletions(-)
480e54
480e54
diff --git a/libdnf/sack/query.cpp b/libdnf/sack/query.cpp
480e54
index 8672275d..205439ec 100644
480e54
--- a/libdnf/sack/query.cpp
480e54
+++ b/libdnf/sack/query.cpp
480e54
@@ -189,6 +189,13 @@ NameArchSolvableComparator(const Solvable * first, const Solvable * second)
480e54
     return first->arch < second->arch;
480e54
 }
480e54
 
480e54
+static bool
480e54
+NameSolvableComparator(const Solvable * first, const Solvable * second)
480e54
+{
480e54
+    return first->name < second->name;
480e54
+}
480e54
+
480e54
+
480e54
 static bool
480e54
 NamePrioritySolvableKey(const Solvable * first, const Solvable * second)
480e54
 {
480e54
@@ -1878,11 +1885,14 @@ Query::Impl::filterAdvisory(const Filter & f, Map *m, int keyname)
480e54
         std::vector<Solvable *> installed_solvables;
480e54
 
480e54
         if (cmp_type & HY_UPGRADE) {
480e54
-            // When doing HY_UPGRADE consider only candidate pkgs that have matching Name and Arch with:
480e54
-            // * some already installed pkg (in other words: some other version of the pkg is already installed)
480e54
-            // or
480e54
-            // * with pkg that obsoletes some already installed (or to be installed in this transaction) pkg
480e54
-            // Otherwise a pkg with different Arch than installed can end up in upgrade set which is wrong.
480e54
+            // When doing HY_UPGRADE consider only candidate pkgs that:
480e54
+            // * have matching Name and Arch with some already installed pkg
480e54
+            //   (in other words: some other version of the pkg is already installed)
480e54
+            // * have matching Name with some already installed pkg and either the candidate or the installed pkg is noarch.
480e54
+            //   This matches upgrade behavior where we allow architecture change only when noarch is involved.
480e54
+            //   Details: RhBug:2124483, RhBug:2101398 and RhBug:1171543
480e54
+            // * obsoletes some already installed (or to be installed in this transaction) pkg
480e54
+            // Otherwise a pkg with different Arch than installed (and than noarch) can end up in upgrade set which is wrong.
480e54
             // It can result in dependency issues, reported as: RhBug:2088149.
480e54
 
480e54
             Query installed(sack, ExcludeFlags::IGNORE_EXCLUDES);
480e54
@@ -1893,7 +1903,7 @@ Query::Impl::filterAdvisory(const Filter & f, Map *m, int keyname)
480e54
             while ((installed_id = installed.pImpl->result->next(installed_id)) != -1) {
480e54
                 installed_solvables.push_back(pool_id2solvable(pool, installed_id));
480e54
             }
480e54
-            std::sort(installed_solvables.begin(), installed_solvables.end(), NameArchSolvableComparator);
480e54
+            std::sort(installed_solvables.begin(), installed_solvables.end(), NameSolvableComparator);
480e54
 
480e54
             Query obsoletes(sack, ExcludeFlags::IGNORE_EXCLUDES);
480e54
             obsoletes.addFilter(HY_PKG, HY_EQ, resultPset);
480e54
@@ -1915,12 +1925,16 @@ Query::Impl::filterAdvisory(const Filter & f, Map *m, int keyname)
480e54
             }
480e54
 
480e54
             Id id = -1;
480e54
-            // Add to candidates resultPset pkgs that match name and arch with some already installed pkg
480e54
+            // Add to candidates resultPset pkgs that match name and arch with some already installed pkg or match name and either the installed or candidate are NOARCH
480e54
             while ((id = resultPset->next(id)) != -1) {
480e54
                 Solvable * s = pool_id2solvable(pool, id);
480e54
-                auto low = std::lower_bound(installed_solvables.begin(), installed_solvables.end(), s, NameArchSolvableComparator);
480e54
-                if (low != installed_solvables.end() && s->name == (*low)->name && s->arch == (*low)->arch) {
480e54
-                    candidates.push_back(s);
480e54
+                auto low = std::lower_bound(installed_solvables.begin(), installed_solvables.end(), s, NameSolvableComparator);
480e54
+                while (low != installed_solvables.end() && (*low)->name == s->name) {
480e54
+                    if (s->arch == (*low)->arch || s->arch == ARCH_NOARCH || (*low)->arch == ARCH_NOARCH) {
480e54
+                        candidates.push_back(s);
480e54
+                        break;
480e54
+                    }
480e54
+                    ++low;
480e54
                 }
480e54
             }
480e54
 
480e54
-- 
480e54
2.37.3
480e54