Skip to content

Commit 04d4d03

Browse files
committed
Make use of the %_dbpath macro if it is set
1 parent e258226 commit 04d4d03

3 files changed

Lines changed: 11 additions & 0 deletions

File tree

ext/repo_rpmdb.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,8 @@ freestate(struct rpmdbstate *state)
13491349
#ifdef ENABLE_RPMDB
13501350
if (state->dbenvopened)
13511351
closedbenv(state);
1352+
if (state->dbpath_allocated)
1353+
solv_free((char *)state->dbpath);
13521354
#endif
13531355
if (state->rootdir)
13541356
solv_free(state->rootdir);

ext/repo_rpmdb_bdb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ struct rpmdbstate {
4848
int dbenvopened; /* database environment opened */
4949
int pkgdbopened; /* package database openend */
5050
const char *dbpath; /* path to the database */
51+
int dbpath_allocated; /* do we need to free the path? */
5152

5253
DB_ENV *dbenv; /* database environment */
5354
DB *db; /* packages database */

ext/repo_rpmdb_librpm.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct rpmdbstate {
2424

2525
int dbenvopened; /* database environment opened */
2626
const char *dbpath; /* path to the database */
27+
int dbpath_allocated; /* do we need to free the path? */
2728

2829
rpmts ts;
2930
rpmdbMatchIterator mi; /* iterator over packages database */
@@ -45,6 +46,13 @@ access_rootdir(struct rpmdbstate *state, const char *dir, int mode)
4546
static void
4647
detect_dbpath(struct rpmdbstate *state)
4748
{
49+
state->dbpath = rpmExpand("%{?_dbpath}", NULL);
50+
if (state->dbpath && *state->dbpath)
51+
{
52+
state->dbpath_allocated = 1;
53+
return;
54+
}
55+
solv_free((char *)state->dbpath);
4856
state->dbpath = access_rootdir(state, "/var/lib/rpm", W_OK) == -1
4957
&& (access_rootdir(state, "/usr/share/rpm/Packages", R_OK) == 0 || access_rootdir(state, "/usr/share/rpm/rpmdb.sqlite", R_OK) == 0)
5058
? "/usr/share/rpm" : "/var/lib/rpm";

0 commit comments

Comments
 (0)