diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/backend/db3.c | 23 | ||||
-rw-r--r-- | lib/rpmdb.c | 14 | ||||
-rw-r--r-- | lib/rpmdb_internal.h | 9 |
3 files changed, 27 insertions, 19 deletions
diff --git a/lib/backend/db3.c b/lib/backend/db3.c index d15ccf4d0..75ea6c333 100644 --- a/lib/backend/db3.c +++ b/lib/backend/db3.c @@ -155,6 +155,7 @@ static int db_init(dbiIndex dbi, const char * dbhome, DB_ENV ** dbenvp) xx = cvtdberr(dbi, "dbenv->set_mp_mmapsize", xx, _debug); } if (dbi->dbi_tmpdir) { + /* XXX this isn't correct wrt chroot in+out */ const char * root = rpmdb->db_chrootDone ? NULL : rpmdb->db_root; char * tmpdir = rpmGenPath(root, dbi->dbi_tmpdir, NULL); xx = dbenv->set_tmp_dir(dbenv, tmpdir); @@ -388,19 +389,13 @@ static int db3stat(dbiIndex dbi, unsigned int flags) static int db3close(dbiIndex dbi, unsigned int flags) { rpmdb rpmdb = dbi->dbi_rpmdb; - const char * root = rpmdb->db_chrootDone ? NULL : rpmdb->db_root; - char * dbhome; + const char * dbhome = rpmdbHome(rpmdb); DB * db = dbi->dbi_db; int _printit; int rc = 0, xx; flags = 0; /* XXX unused */ - /* - * Get the prefix/root component and directory path. - */ - dbhome = rpmGenPath(root, rpmdb->db_home, NULL); - if (db) { rc = db->close(db, 0); /* XXX ignore not found error messages. */ @@ -443,6 +438,8 @@ static int db3close(dbiIndex dbi, unsigned int flags) (dbi->dbi_verbose & DB_VERB_WAITSFOR)); if (dbi->dbi_tmpdir) { + /* XXX this isn't correct wrt chroot in+out */ + const char * root = rpmdb->db_chrootDone ? NULL : rpmdb->db_root; char * tmpdir = rpmGenPath(root, dbi->dbi_tmpdir, NULL); rc = dbenv->set_tmp_dir(dbenv, tmpdir); rc = cvtdberr(dbi, "dbenv->set_tmp_dir", rc, _debug); @@ -482,8 +479,6 @@ static int db3close(dbiIndex dbi, unsigned int flags) exit: dbi->dbi_db = NULL; - free(dbhome); - dbi = db3Free(dbi); return rc; @@ -492,8 +487,7 @@ exit: static int db3open(rpmdb rpmdb, rpmTag rpmtag, dbiIndex * dbip) { extern const struct _dbiVec db3vec; - const char * root = rpmdb->db_chrootDone ? NULL : rpmdb->db_root; - char * dbhome; + const char *dbhome = rpmdbHome(rpmdb); dbiIndex dbi = NULL; int rc = 0; int xx; @@ -513,11 +507,6 @@ static int db3open(rpmdb rpmdb, rpmTag rpmtag, dbiIndex * dbip) if ((dbi = db3New(rpmdb, rpmtag)) == NULL) return 1; - /* - * Get the prefix/root component and directory path. - */ - dbhome = rpmGenPath(root, rpmdb->db_home, NULL); - oflags = (dbi->dbi_oeflags | dbi->dbi_oflags); oflags &= ~DB_TRUNCATE; /* XXX this is dangerous */ @@ -859,8 +848,6 @@ static int db3open(rpmdb rpmdb, rpmTag rpmtag, dbiIndex * dbip) (void) db3close(dbi, 0); } - free(dbhome); - return rc; } diff --git a/lib/rpmdb.c b/lib/rpmdb.c index 1bce765a7..ff5d865ec 100644 --- a/lib/rpmdb.c +++ b/lib/rpmdb.c @@ -714,6 +714,7 @@ static int unblockSignals(sigset_t * oldMask) #define _DB_ROOT "/" #define _DB_HOME "%{_dbpath}" +#define _DB_FULLPATH NULL #define _DB_FLAGS 0 #define _DB_MODE 0 #define _DB_PERMS 0644 @@ -722,7 +723,7 @@ static int unblockSignals(sigset_t * oldMask) #define _DB_ERRPFX "rpmdb" static struct rpmdb_s const dbTemplate = { - _DB_ROOT, _DB_HOME, _DB_FLAGS, _DB_MODE, _DB_PERMS, + _DB_ROOT, _DB_HOME, _DB_FULLPATH, _DB_FLAGS, _DB_MODE, _DB_PERMS, _DB_MAJOR, _DB_ERRPFX }; @@ -761,6 +762,15 @@ rpmop rpmdbOp(rpmdb rpmdb, rpmdbOpX opx) return op; } +const char *rpmdbHome(rpmdb db) +{ + const char *dbdir = NULL; + if (db) { + dbdir = db->db_chrootDone ? db->db_home : db->db_fullpath; + } + return dbdir; +} + int rpmdbSetChrootDone(rpmdb db, int chrootDone) { int ochrootDone = 0; @@ -840,6 +850,7 @@ int rpmdbClose(rpmdb db) db->db_errpfx = _free(db->db_errpfx); db->db_root = _free(db->db_root); db->db_home = _free(db->db_home); + db->db_fullpath = _free(db->db_fullpath); db->db_bits = PBM_FREE(db->db_bits); db->_dbi = _free(db->_dbi); @@ -915,6 +926,7 @@ rpmdb newRpmdb(const char * root, return NULL; } db->db_root = rpmGetPath((root && *root) ? root : _DB_ROOT, NULL); + db->db_fullpath = rpmGenPath(db->db_root, db->db_home, NULL); db->db_errpfx = rpmExpand( (epfx && *epfx ? epfx : _DB_ERRPFX), NULL); /* XXX remove environment after chrooted operations, for now... */ db->db_remove_env = (!rstreq(db->db_root, "/") ? 1 : 0); diff --git a/lib/rpmdb_internal.h b/lib/rpmdb_internal.h index de7c23f31..f4f1a64d3 100644 --- a/lib/rpmdb_internal.h +++ b/lib/rpmdb_internal.h @@ -256,6 +256,7 @@ unsigned char * dbi_lk_conflicts; struct rpmdb_s { char * db_root;/*!< path prefix */ char * db_home;/*!< directory path */ + char * db_fullpath; /*!< full db path including prefix */ int db_flags; int db_mode; /*!< open mode */ int db_perms; /*!< open permissions */ @@ -524,6 +525,14 @@ RPM_GNUC_INTERNAL unsigned int dbiIndexRecordFileNumber(dbiIndexSet set, int recno); /** \ingroup rpmdb + * Return rpmdb home directory (depending on chroot state) + * param db rpmdb handle + * return db home directory (or NULL on error) + */ +RPM_GNUC_INTERNAL +const char *rpmdbHome(rpmdb db); + +/** \ingroup rpmdb * Return database iterator. * @param mi rpm database iterator * @param keyp key data (NULL for sequential access) |