Skip to content

Commit

Permalink
Use rpm.TransactionSet.dbCookie() to determining if rpmdb has changed
Browse files Browse the repository at this point in the history
DNF was using private method `hawkey.Sack._rpmdb_version()` from libdnf.
The method computes SHA1 hash from sorted list of hashes stored in
the headers of the instaled packages. And it adds prefix of the number
of installed packages to the computed hash. The result was stored
to the history database and used to detect changes in the rpm database.

The patch uses new oficial librpm API function
`rpm.TransactionSet.dbCookie()`. This is a cleaner solution.
It is also a step to remove the `._rpmdb_version()` method from libdnf.
It is an attempt to remove SHA1 calculations from libdnf.
Troubleshooting FIPS compatibility.

= changelog =
msg: Use rpm.TransactionSet.dbCookie() to determining if rpmdb has changed
type: bugfix
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2043476
  • Loading branch information
jrohel authored and j-mracek committed Feb 4, 2022
1 parent bc70d93 commit b975859
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion VERSION.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set (DEFAULT_DNF_VERSION "4.10.1")
set (DEFAULT_DNF_VERSION "4.11.0")

if(DEFINED DNF_VERSION)
if(NOT ${DEFAULT_DNF_VERSION} STREQUAL ${DNF_VERSION})
Expand Down
4 changes: 2 additions & 2 deletions dnf.spec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
%global rpm_version 4.14.0

# conflicts
%global conflicts_dnf_plugins_core_version 4.0.20
%global conflicts_dnf_plugins_core_version 4.0.26
%global conflicts_dnf_plugins_extras_version 4.0.4
%global conflicts_dnfdaemon_version 0.3.19

Expand Down Expand Up @@ -65,7 +65,7 @@
It supports RPMs, modules and comps groups & environments.

Name: dnf
Version: 4.10.1
Version: 4.11.0
Release: 1%{?dist}
Summary: %{pkg_summary}
# For a breakdown of the licensing, see PACKAGE-LICENSING
Expand Down
6 changes: 3 additions & 3 deletions dnf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ def do_transaction(self, display=()):
cmdline = ' '.join(self.cmds)
old = self.history.last()
if old is None:
rpmdb_version = self.sack._rpmdb_version()
rpmdb_version = self._ts.dbCookie()
else:
rpmdb_version = old.end_rpmdb_version

Expand Down Expand Up @@ -1046,7 +1046,7 @@ def _run_transaction(self, cb):
using_pkgs_pats = list(self.conf.history_record_packages)
installed_query = self.sack.query().installed()
using_pkgs = installed_query.filter(name=using_pkgs_pats).run()
rpmdbv = self.sack._rpmdb_version()
rpmdbv = self._ts.dbCookie()
lastdbv = self.history.last()
if lastdbv is not None:
lastdbv = lastdbv.end_rpmdb_version
Expand Down Expand Up @@ -1163,7 +1163,7 @@ def display_banner(pkg, count):
for tsi in transaction_items:
count = display_banner(tsi.pkg, count)

rpmdbv = rpmdb_sack._rpmdb_version()
rpmdbv = self._ts.dbCookie()
self.history.end(rpmdbv)

timer()
Expand Down
2 changes: 1 addition & 1 deletion dnf/cli/commands/mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def run(self):

old = self.base.history.last()
if old is None:
rpmdb_version = self.base.sack._rpmdb_version()
rpmdb_version = self.base._ts.dbCookie()
else:
rpmdb_version = old.end_rpmdb_version

Expand Down
2 changes: 1 addition & 1 deletion dnf/cli/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -1607,7 +1607,7 @@ def historyInfoCmd(self, tids, pats=[], mtids=set()):
if lastdbv is not None and trans.tid == lasttid:
# If this is the last transaction, is good and it doesn't
# match the current rpmdb ... then mark it as bad.
rpmdbv = self.sack._rpmdb_version()
rpmdbv = self.base._ts.dbCookie()
trans.compare_rpmdbv(str(rpmdbv))
lastdbv = None

Expand Down
16 changes: 16 additions & 0 deletions dnf/rpm/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
from __future__ import absolute_import
from __future__ import unicode_literals
from dnf.i18n import _
import logging
import rpm

_logger = logging.getLogger('dnf')
read_ts = None
ts = None

Expand Down Expand Up @@ -61,6 +63,20 @@ def dbMatch(self, *args, **kwds):
mi.pattern(tag, tp, pat)
return mi

def dbCookie(self):
# dbCookie() does not support lazy opening of rpm database.
# The following line opens the database if it is not already open.
if self.ts.openDB() != 0:
_logger.error(_('The openDB() function connot open rpm database.'))
return ''

cookie = self.ts.dbCookie()
if not cookie:
_logger.error(_('The dbCookie() function did not return cookie of rpm database.'))
return ''

return cookie

def __getattr__(self, attr):
if attr in self._methods:
return self.getMethod(attr)
Expand Down
6 changes: 0 additions & 6 deletions tests/test_sack.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ class SackTest(tests.support.DnfBaseTestCase):

REPOS = []

def test_rpmdb_version(self):
version = self.sack._rpmdb_version()
self.assertIsNotNone(version)
expected = "%s:%s" % (tests.support.TOTAL_RPMDB_COUNT, tests.support.RPMDB_CHECKSUM)
self.assertEqual(version, expected)

def test_excludepkgs(self):
self.base.conf.excludepkgs = ['pepper']
self.base._setup_excludes_includes()
Expand Down

0 comments on commit b975859

Please sign in to comment.