Blame SOURCES/0038-Better-explain-traceback-of-rpm.error-with-dnf.patch

eb8139
From f1fbef17862e033bf9518bd318339b405f2664dd Mon Sep 17 00:00:00 2001
eb8139
From: Nicola Sella <nsella@redhat.com>
eb8139
Date: Mon, 22 Mar 2021 17:37:51 +0100
eb8139
Subject: [PATCH 1/2] Better explain traceback of rpm.error with dnf
eb8139
eb8139
=changelog=
eb8139
msg: Add dnf.error message to explain rpm.error traceback when package not found after resolving a transaction
eb8139
type: bugfix
eb8139
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1815327
eb8139
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1887293
eb8139
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1909845
eb8139
---
eb8139
 dnf/db/group.py | 78 ++++++++++++++++++++++++++-----------------------
eb8139
 1 file changed, 41 insertions(+), 37 deletions(-)
eb8139
eb8139
diff --git a/dnf/db/group.py b/dnf/db/group.py
eb8139
index 312e3b98..3a17019a 100644
eb8139
--- a/dnf/db/group.py
eb8139
+++ b/dnf/db/group.py
eb8139
@@ -26,6 +26,7 @@ import dnf.exceptions
eb8139
 from dnf.i18n import _
eb8139
 from dnf.util import logger
eb8139
 
eb8139
+import rpm
eb8139
 
eb8139
 class PersistorBase(object):
eb8139
     def __init__(self, history):
eb8139
@@ -316,43 +317,46 @@ class RPMTransaction(object):
eb8139
         modular_problems = 0
eb8139
 
eb8139
         for tsi in self:
eb8139
-            if tsi.action == libdnf.transaction.TransactionItemAction_DOWNGRADE:
eb8139
-                hdr = tsi.pkg._header
eb8139
-                modular_problems += self._test_fail_safe(hdr, tsi.pkg)
eb8139
-                ts.addInstall(hdr, tsi, 'u')
eb8139
-            elif tsi.action == libdnf.transaction.TransactionItemAction_DOWNGRADED:
eb8139
-                ts.addErase(tsi.pkg.idx)
eb8139
-            elif tsi.action == libdnf.transaction.TransactionItemAction_INSTALL:
eb8139
-                hdr = tsi.pkg._header
eb8139
-                modular_problems += self._test_fail_safe(hdr, tsi.pkg)
eb8139
-                ts.addInstall(hdr, tsi, 'i')
eb8139
-            elif tsi.action == libdnf.transaction.TransactionItemAction_OBSOLETE:
eb8139
-                hdr = tsi.pkg._header
eb8139
-                modular_problems += self._test_fail_safe(hdr, tsi.pkg)
eb8139
-                ts.addInstall(hdr, tsi, 'u')
eb8139
-            elif tsi.action == libdnf.transaction.TransactionItemAction_OBSOLETED:
eb8139
-                ts.addErase(tsi.pkg.idx)
eb8139
-            elif tsi.action == libdnf.transaction.TransactionItemAction_REINSTALL:
eb8139
-                # note: in rpm 4.12 there should not be set
eb8139
-                # rpm.RPMPROB_FILTER_REPLACEPKG to work
eb8139
-                hdr = tsi.pkg._header
eb8139
-                modular_problems += self._test_fail_safe(hdr, tsi.pkg)
eb8139
-                ts.addReinstall(hdr, tsi)
eb8139
-            elif tsi.action == libdnf.transaction.TransactionItemAction_REINSTALLED:
eb8139
-                # Required when multiple packages with the same NEVRA marked as installed
eb8139
-                ts.addErase(tsi.pkg.idx)
eb8139
-            elif tsi.action == libdnf.transaction.TransactionItemAction_REMOVE:
eb8139
-                ts.addErase(tsi.pkg.idx)
eb8139
-            elif tsi.action == libdnf.transaction.TransactionItemAction_UPGRADE:
eb8139
-                hdr = tsi.pkg._header
eb8139
-                modular_problems += self._test_fail_safe(hdr, tsi.pkg)
eb8139
-                ts.addInstall(hdr, tsi, 'u')
eb8139
-            elif tsi.action == libdnf.transaction.TransactionItemAction_UPGRADED:
eb8139
-                ts.addErase(tsi.pkg.idx)
eb8139
-            elif tsi.action == libdnf.transaction.TransactionItemAction_REASON_CHANGE:
eb8139
-                pass
eb8139
-            else:
eb8139
-                raise RuntimeError("TransactionItemAction not handled: %s" % tsi.action)
eb8139
+            try:
eb8139
+                if tsi.action == libdnf.transaction.TransactionItemAction_DOWNGRADE:
eb8139
+                    hdr = tsi.pkg._header
eb8139
+                    modular_problems += self._test_fail_safe(hdr, tsi.pkg)
eb8139
+                    ts.addInstall(hdr, tsi, 'u')
eb8139
+                elif tsi.action == libdnf.transaction.TransactionItemAction_DOWNGRADED:
eb8139
+                    ts.addErase(tsi.pkg.idx)
eb8139
+                elif tsi.action == libdnf.transaction.TransactionItemAction_INSTALL:
eb8139
+                    hdr = tsi.pkg._header
eb8139
+                    modular_problems += self._test_fail_safe(hdr, tsi.pkg)
eb8139
+                    ts.addInstall(hdr, tsi, 'i')
eb8139
+                elif tsi.action == libdnf.transaction.TransactionItemAction_OBSOLETE:
eb8139
+                    hdr = tsi.pkg._header
eb8139
+                    modular_problems += self._test_fail_safe(hdr, tsi.pkg)
eb8139
+                    ts.addInstall(hdr, tsi, 'u')
eb8139
+                elif tsi.action == libdnf.transaction.TransactionItemAction_OBSOLETED:
eb8139
+                    ts.addErase(tsi.pkg.idx)
eb8139
+                elif tsi.action == libdnf.transaction.TransactionItemAction_REINSTALL:
eb8139
+                    # note: in rpm 4.12 there should not be set
eb8139
+                    # rpm.RPMPROB_FILTER_REPLACEPKG to work
eb8139
+                    hdr = tsi.pkg._header
eb8139
+                    modular_problems += self._test_fail_safe(hdr, tsi.pkg)
eb8139
+                    ts.addReinstall(hdr, tsi)
eb8139
+                elif tsi.action == libdnf.transaction.TransactionItemAction_REINSTALLED:
eb8139
+                    # Required when multiple packages with the same NEVRA marked as installed
eb8139
+                    ts.addErase(tsi.pkg.idx)
eb8139
+                elif tsi.action == libdnf.transaction.TransactionItemAction_REMOVE:
eb8139
+                    ts.addErase(tsi.pkg.idx)
eb8139
+                elif tsi.action == libdnf.transaction.TransactionItemAction_UPGRADE:
eb8139
+                    hdr = tsi.pkg._header
eb8139
+                    modular_problems += self._test_fail_safe(hdr, tsi.pkg)
eb8139
+                    ts.addInstall(hdr, tsi, 'u')
eb8139
+                elif tsi.action == libdnf.transaction.TransactionItemAction_UPGRADED:
eb8139
+                    ts.addErase(tsi.pkg.idx)
eb8139
+                elif tsi.action == libdnf.transaction.TransactionItemAction_REASON_CHANGE:
eb8139
+                    pass
eb8139
+                else:
eb8139
+                    raise RuntimeError("TransactionItemAction not handled: %s" % tsi.action)
eb8139
+            except rpm.error as e:
eb8139
+                raise dnf.exceptions.Error(_("An rpm exception occurred: %s" % e))
eb8139
         if modular_problems:
eb8139
             raise dnf.exceptions.Error(_("No available modular metadata for modular package"))
eb8139
 
eb8139
-- 
eb8139
2.39.0
eb8139