Skip to content

Commit

Permalink
context, sack: Support all rpmdb path variants
Browse files Browse the repository at this point in the history
We rely on identifying whether the rpmdb path has changed to
determine whether we need to re-cache data from there. Now
that RPM has multiple rpmdb options and there are two common
paths in use by RPM-based systems, we need to handle all of
these.
  • Loading branch information
Conan-Kudo committed Mar 22, 2020
1 parent 639962f commit 9584c58
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
23 changes: 22 additions & 1 deletion libdnf/dnf-context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2094,6 +2094,15 @@ dnf_context_setup(DnfContext *context,
g_autoptr(GString) buf = NULL;
g_autofree char *rpmdb_path = NULL;
g_autoptr(GFile) file_rpmdb = NULL;
const gchar *rpmdb_path_variants[] = { "var/lib/rpm/rpmdb.sqlite",
"usr/lib/sysimage/rpm/rpmdb.sqlite",
"var/lib/rpm/Packages.db",
"usr/lib/sysimage/rpm/Packages.db",
"var/lib/rpm/Packages",
"usr/lib/sysimage/rpm/Packages",
"var/lib/rpm/data.mdb",
"usr/lib/sysimage/rpm/data.mdb",
NULL };

if (libdnf::getGlobalMainConfig().plugins().getValue() && !pluginsDir.empty()) {
priv->plugins->loadPlugins(pluginsDir);
Expand Down Expand Up @@ -2177,9 +2186,21 @@ dnf_context_setup(DnfContext *context,
!dnf_context_set_os_release(context, error))
return FALSE;

/* identify correct rpmdb file */
for (i = 0; rpmdb_path_variants[i] != NULL; i++) {
rpmdb_path = g_build_filename(priv->install_root, rpmdb_path_variants[i], NULL);
if (g_file_test(rpmdb_path, G_FILE_TEST_EXISTS))
break;
rpmdb_path = NULL;
}

/* if we can't identify an rpmdb path for any reason, fallback to legacy value */
if (rpmdb_path == NULL) {
rpmdb_path = g_build_filename(priv->install_root, "var/lib/rpm/Packages", NULL);
}

/* setup a file monitor on the rpmdb, if we're operating on the native / */
if (g_strcmp0(priv->install_root, "/") == 0) {
rpmdb_path = g_build_filename(priv->install_root, "var/lib/rpm/Packages", NULL);
file_rpmdb = g_file_new_for_path(rpmdb_path);
priv->monitor_rpmdb = g_file_monitor_file(file_rpmdb,
G_FILE_MONITOR_NONE,
Expand Down
9 changes: 8 additions & 1 deletion libdnf/dnf-sack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,14 @@ dnf_sack_new(void)
static int
current_rpmdb_checksum(Pool *pool, unsigned char csout[CHKSUM_BYTES])
{
const char *rpmdb_prefix_paths[] = { "/var/lib/rpm/Packages",
const char *rpmdb_prefix_paths[] = { "/var/lib/rpm/rpmdb.sqlite",
"/usr/lib/sysimage/rpm/rpmdb.sqlite",
"/var/lib/rpm/Packages.db",
"/usr/lib/sysimage/rpm/Packages.db",
"/var/lib/rpm/Packages",
"/usr/lib/sysimage/rpm/Packages",
"/var/lib/rpm/data.mdb",
"/usr/lib/sysimage/rpm/data.mdb",
"/usr/share/rpm/Packages" };
unsigned int i;
const char *fn;
Expand Down

0 comments on commit 9584c58

Please sign in to comment.