richardphibel / rpms / dnf

Forked from rpms/dnf 2 years ago
Clone

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

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