Blame SOURCES/0004-Use-rpm.TransactionSet.dbCookie-to-determining-if-rp.patch

5a9274
From 087ad3d12ba307355dd66aba54faea97d227a3dd Mon Sep 17 00:00:00 2001
5a9274
From: zhanghaolian <65838930+iWhy98@users.noreply.github.com>
5a9274
Date: Tue, 25 Jan 2022 15:41:16 +0800
5a9274
Subject: [PATCH 1/2] dnf:fix dnf mark error when history sqlite missing
5a9274
5a9274
---
5a9274
 dnf/cli/commands/mark.py | 2 +-
5a9274
 1 file changed, 1 insertion(+), 1 deletion(-)
5a9274
5a9274
diff --git a/dnf/cli/commands/mark.py b/dnf/cli/commands/mark.py
5a9274
index ec16b738d..cb1f91c13 100644
5a9274
--- a/dnf/cli/commands/mark.py
5a9274
+++ b/dnf/cli/commands/mark.py
5a9274
@@ -89,7 +89,7 @@ class MarkCommand(commands.Command):
5a9274
 
5a9274
         old = self.base.history.last()
5a9274
         if old is None:
5a9274
-            rpmdb_version = self.sack._rpmdb_version()
5a9274
+            rpmdb_version = self.base.sack._rpmdb_version()
5a9274
         else:
5a9274
             rpmdb_version = old.end_rpmdb_version
5a9274
 
5a9274
-- 
5a9274
2.34.1
5a9274
5a9274
5a9274
From bee5b97ad159af019deda4de0d80d0011dba4f7a Mon Sep 17 00:00:00 2001
5a9274
From: Jaroslav Rohel <jrohel@redhat.com>
5a9274
Date: Fri, 28 Jan 2022 16:53:50 +0100
5a9274
Subject: [PATCH 2/2] Use rpm.TransactionSet.dbCookie() to determining if rpmdb
5a9274
 has changed
5a9274
5a9274
DNF was using private method `hawkey.Sack._rpmdb_version()` from libdnf.
5a9274
The method computes SHA1 hash from sorted list of hashes stored in
5a9274
the headers of the instaled packages. And it adds prefix of the number
5a9274
of installed packages to the computed hash. The result was stored
5a9274
to the history database and used to detect changes in the rpm database.
5a9274
5a9274
The patch uses new oficial librpm API function
5a9274
`rpm.TransactionSet.dbCookie()`. This is a cleaner solution.
5a9274
It is also a step to remove the `._rpmdb_version()` method from libdnf.
5a9274
It is an attempt to remove SHA1 calculations from libdnf.
5a9274
Troubleshooting FIPS compatibility.
5a9274
5a9274
= changelog =
5a9274
msg: Use rpm.TransactionSet.dbCookie() to determining if rpmdb has changed
5a9274
type: bugfix
5a9274
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2043476
5a9274
---
5a9274
 dnf/base.py              |  6 +++---
5a9274
 dnf/cli/commands/mark.py |  2 +-
5a9274
 dnf/cli/output.py        |  2 +-
5a9274
 dnf/rpm/transaction.py   | 16 ++++++++++++++++
5a9274
 tests/test_sack.py       |  6 ------
5a9274
 5 files changed, 21 insertions(+), 11 deletions(-)
5a9274
5a9274
diff --git a/dnf/base.py b/dnf/base.py
5a9274
index b0a536f7f..574e80f66 100644
5a9274
--- a/dnf/base.py
5a9274
+++ b/dnf/base.py
5a9274
@@ -907,7 +907,7 @@ class Base(object):
5a9274
                     cmdline = ' '.join(self.cmds)
5a9274
                 old = self.history.last()
5a9274
                 if old is None:
5a9274
-                    rpmdb_version = self.sack._rpmdb_version()
5a9274
+                    rpmdb_version = self._ts.dbCookie()
5a9274
                 else:
5a9274
                     rpmdb_version = old.end_rpmdb_version
5a9274
 
5a9274
@@ -1046,7 +1046,7 @@ class Base(object):
5a9274
             using_pkgs_pats = list(self.conf.history_record_packages)
5a9274
             installed_query = self.sack.query().installed()
5a9274
             using_pkgs = installed_query.filter(name=using_pkgs_pats).run()
5a9274
-            rpmdbv = self.sack._rpmdb_version()
5a9274
+            rpmdbv = self._ts.dbCookie()
5a9274
             lastdbv = self.history.last()
5a9274
             if lastdbv is not None:
5a9274
                 lastdbv = lastdbv.end_rpmdb_version
5a9274
@@ -1163,7 +1163,7 @@ class Base(object):
5a9274
         for tsi in transaction_items:
5a9274
             count = display_banner(tsi.pkg, count)
5a9274
 
5a9274
-        rpmdbv = rpmdb_sack._rpmdb_version()
5a9274
+        rpmdbv = self._ts.dbCookie()
5a9274
         self.history.end(rpmdbv)
5a9274
 
5a9274
         timer()
5a9274
diff --git a/dnf/cli/commands/mark.py b/dnf/cli/commands/mark.py
5a9274
index cb1f91c13..36bf9d436 100644
5a9274
--- a/dnf/cli/commands/mark.py
5a9274
+++ b/dnf/cli/commands/mark.py
5a9274
@@ -89,7 +89,7 @@ class MarkCommand(commands.Command):
5a9274
 
5a9274
         old = self.base.history.last()
5a9274
         if old is None:
5a9274
-            rpmdb_version = self.base.sack._rpmdb_version()
5a9274
+            rpmdb_version = self.base._ts.dbCookie()
5a9274
         else:
5a9274
             rpmdb_version = old.end_rpmdb_version
5a9274
 
5a9274
diff --git a/dnf/cli/output.py b/dnf/cli/output.py
5a9274
index a4e9f6c8e..ecf05c2b0 100644
5a9274
--- a/dnf/cli/output.py
5a9274
+++ b/dnf/cli/output.py
5a9274
@@ -1607,7 +1607,7 @@ Transaction Summary
5a9274
             if lastdbv is not None and trans.tid == lasttid:
5a9274
                 #  If this is the last transaction, is good and it doesn't
5a9274
                 # match the current rpmdb ... then mark it as bad.
5a9274
-                rpmdbv = self.sack._rpmdb_version()
5a9274
+                rpmdbv = self.base._ts.dbCookie()
5a9274
                 trans.compare_rpmdbv(str(rpmdbv))
5a9274
             lastdbv = None
5a9274
 
5a9274
diff --git a/dnf/rpm/transaction.py b/dnf/rpm/transaction.py
5a9274
index bcc2a7024..a11f36e7e 100644
5a9274
--- a/dnf/rpm/transaction.py
5a9274
+++ b/dnf/rpm/transaction.py
5a9274
@@ -12,8 +12,10 @@
5a9274
 from __future__ import absolute_import
5a9274
 from __future__ import unicode_literals
5a9274
 from dnf.i18n import _
5a9274
+import logging
5a9274
 import rpm
5a9274
 
5a9274
+_logger = logging.getLogger('dnf')
5a9274
 read_ts = None
5a9274
 ts = None
5a9274
 
5a9274
@@ -61,6 +63,20 @@ class TransactionWrapper(object):
5a9274
             mi.pattern(tag, tp, pat)
5a9274
         return mi
5a9274
 
5a9274
+    def dbCookie(self):
5a9274
+        # dbCookie() does not support lazy opening of rpm database.
5a9274
+        # The following line opens the database if it is not already open.
5a9274
+        if self.ts.openDB() != 0:
5a9274
+            _logger.error(_('The openDB() function connot open rpm database.'))
5a9274
+            return ''
5a9274
+
5a9274
+        cookie = self.ts.dbCookie()
5a9274
+        if not cookie:
5a9274
+            _logger.error(_('The dbCookie() function did not return cookie of rpm database.'))
5a9274
+            return ''
5a9274
+
5a9274
+        return cookie
5a9274
+
5a9274
     def __getattr__(self, attr):
5a9274
         if attr in self._methods:
5a9274
             return self.getMethod(attr)
5a9274
diff --git a/tests/test_sack.py b/tests/test_sack.py
5a9274
index 49a715924..2c6fe8e01 100644
5a9274
--- a/tests/test_sack.py
5a9274
+++ b/tests/test_sack.py
5a9274
@@ -32,12 +32,6 @@ class SackTest(tests.support.DnfBaseTestCase):
5a9274
 
5a9274
     REPOS = []
5a9274
 
5a9274
-    def test_rpmdb_version(self):
5a9274
-        version = self.sack._rpmdb_version()
5a9274
-        self.assertIsNotNone(version)
5a9274
-        expected = "%s:%s" % (tests.support.TOTAL_RPMDB_COUNT, tests.support.RPMDB_CHECKSUM)
5a9274
-        self.assertEqual(version, expected)
5a9274
-
5a9274
     def test_excludepkgs(self):
5a9274
         self.base.conf.excludepkgs = ['pepper']
5a9274
         self.base._setup_excludes_includes()
5a9274
-- 
5a9274
2.34.1
5a9274