Blame SOURCES/0025-Add-only-relevant-pkgs-to-upgrade-transaction-RhBug-.patch

52b19a
From 25bc75cbe63289864c09ab25144ee4af232bd8f4 Mon Sep 17 00:00:00 2001
52b19a
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
52b19a
Date: Mon, 4 Jul 2022 09:43:25 +0200
52b19a
Subject: [PATCH] Add only relevant pkgs to upgrade transaction (RhBug:2097757)
52b19a
52b19a
https://bugzilla.redhat.com/show_bug.cgi?id=2097757
52b19a
52b19a
Without this patch dnf can create the following transaction during dnf upgrade --security when there is an advisory for B-2-2:
52b19a
52b19a
```
52b19a
repo @System 0 testtags <inline>
52b19a
#>=Pkg: A 1 1 x86_64
52b19a
#>=Pkg: B 1 1 x86_64
52b19a
#>=Req: A = 1-1
52b19a
52b19a
repo available 0 testtags <inline>
52b19a
#>=Pkg: A 2 2 x86_64
52b19a
#>=Pkg: B 2 2 x86_64
52b19a
#>=Req: A = 2-2
52b19a
system x86_64 rpm @System
52b19a
job update oneof A-1-1.x86_64@@System B-2-2.x86_64@available [targeted,setevr,setarch]
52b19a
result transaction,problems
52b19a
```
52b19a
52b19a
Problem is that without forcebest nothing gets upgraded despite the available advisory and --security switch.
52b19a
52b19a
This can also be seen in CI test case: rpm-software-management/ci-dnf-stack#1130
52b19a
---
52b19a
 dnf/base.py | 19 ++++++++++++++++++-
52b19a
 1 file changed, 18 insertions(+), 1 deletion(-)
52b19a
52b19a
diff --git a/dnf/base.py b/dnf/base.py
52b19a
index 852fcdd8..82466831 100644
52b19a
--- a/dnf/base.py
52b19a
+++ b/dnf/base.py
52b19a
@@ -2135,7 +2135,24 @@ class Base(object):
52b19a
             query.filterm(reponame=reponame)
52b19a
         query = self._merge_update_filters(query, pkg_spec=pkg_spec, upgrade=True)
52b19a
         if query:
52b19a
-            query = query.union(installed_query.latest())
52b19a
+            # Given that we use libsolv's targeted transactions, we need to ensure that the transaction contains both
52b19a
+            # the new targeted version and also the current installed version (for the upgraded package). This is
52b19a
+            # because if it only contained the new version, libsolv would decide to reinstall the package even if it
52b19a
+            # had just a different buildtime or vendor but the same version
52b19a
+            # (https://github.com/openSUSE/libsolv/issues/287)
52b19a
+            #   - In general, the query already contains both the new and installed versions but not always.
52b19a
+            #     If repository-packages command is used, the installed packages are filtered out because they are from
52b19a
+            #     the @system repo. We need to add them back in.
52b19a
+            #   - However we need to add installed versions of just the packages that are being upgraded. We don't want
52b19a
+            #     to add all installed packages because it could increase the number of solutions for the transaction
52b19a
+            #     (especially without --best) and since libsolv prefers the smallest possible upgrade it could result
52b19a
+            #     in no upgrade even if there is one available. This is a problem in general but its critical with
52b19a
+            #     --security transactions (https://bugzilla.redhat.com/show_bug.cgi?id=2097757)
52b19a
+            #   - We want to add only the latest versions of installed packages, this is specifically for installonly
52b19a
+            #     packages. Otherwise if for example kernel-1 and kernel-3 were installed and present in the
52b19a
+            #     transaction libsolv could decide to install kernel-2 because it is an upgrade for kernel-1 even
52b19a
+            #     though we don't want it because there already is a newer version present.
52b19a
+            query = query.union(installed_query.latest().filter(name=[pkg.name for pkg in query]))
52b19a
             sltr = dnf.selector.Selector(self.sack)
52b19a
             sltr.set(pkg=query)
52b19a
             self._goal.upgrade(select=sltr)
52b19a
-- 
52b19a
2.36.1
52b19a