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

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