]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
Make use of the %_dbpath macro if it is set
authorMichael Schroeder <mls@suse.de>
Wed, 18 Nov 2020 12:09:36 +0000 (13:09 +0100)
committerMichael Schroeder <mls@suse.de>
Wed, 18 Nov 2020 12:09:36 +0000 (13:09 +0100)
ext/repo_rpmdb.c
ext/repo_rpmdb_bdb.h
ext/repo_rpmdb_librpm.h

index 67ce81daf1e4ef2e5b6f7bdf8e4a03d393b72991..d78893ee22506684404a4e6a2a439e32fd68206c 100644 (file)
@@ -1349,6 +1349,8 @@ freestate(struct rpmdbstate *state)
 #ifdef ENABLE_RPMDB
   if (state->dbenvopened)
     closedbenv(state);
+  if (state->dbpath_allocated)
+    solv_free((char *)state->dbpath);
 #endif
   if (state->rootdir)
     solv_free(state->rootdir);
index 1c833171fdfd86f3a8ffb8ed5cd92096e7d35239..4043ef1b22219f4d47411ac5e716d974a6b8a090 100644 (file)
@@ -48,6 +48,7 @@ struct rpmdbstate {
   int dbenvopened;     /* database environment opened */
   int pkgdbopened;     /* package database openend */
   const char *dbpath;  /* path to the database */
+  int dbpath_allocated;        /* do we need to free the path? */
 
   DB_ENV *dbenv;       /* database environment */
   DB *db;              /* packages database */
index 35a46face86ba26e154788e1b43e5b0401973d0f..e326e8d7049f683ea696d5166b97dc2e77b2b4da 100644 (file)
@@ -24,6 +24,7 @@ struct rpmdbstate {
 
   int dbenvopened;     /* database environment opened */
   const char *dbpath;  /* path to the database */
+  int dbpath_allocated;        /* do we need to free the path? */
 
   rpmts ts;
   rpmdbMatchIterator mi;       /* iterator over packages database */
@@ -45,6 +46,13 @@ access_rootdir(struct rpmdbstate *state, const char *dir, int mode)
 static void
 detect_dbpath(struct rpmdbstate *state)
 {
+  state->dbpath = rpmExpand("%{?_dbpath}", NULL);
+  if (state->dbpath && *state->dbpath)
+    {
+      state->dbpath_allocated = 1;
+      return;
+    }
+  solv_free((char *)state->dbpath);
   state->dbpath = access_rootdir(state, "/var/lib/rpm", W_OK) == -1
                   && (access_rootdir(state, "/usr/share/rpm/Packages", R_OK) == 0 || access_rootdir(state, "/usr/share/rpm/rpmdb.sqlite", R_OK) == 0)
                   ? "/usr/share/rpm" : "/var/lib/rpm";