From bf8cfe884bf24f531f9b318bc8288951a07802c9 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Wed, 20 Oct 2010 12:13:33 +0300 Subject: [PATCH] Clean up rpmdbOpenIndex() logic a bit, no functional changes - dbi is guaranteed to be NULL on non-zero return from dbiOpen(), dont bother triple-checking and freeing NULLs - rearrange the success case a bit to pave way for other things that we'll want to do here --- lib/rpmdb.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/rpmdb.c b/lib/rpmdb.c index 66dbbdb..5394053 100644 --- a/lib/rpmdb.c +++ b/lib/rpmdb.c @@ -190,26 +190,23 @@ static dbiIndex rpmdbOpenIndex(rpmdb db, rpmTag rpmtag, int flags) errno = 0; dbi = NULL; rc = dbiOpen(db, rpmtag, &dbi, flags); + if (rc) { static int _printed[32]; if (!_printed[dbix & 0x1f]++) - rpmlog(RPMLOG_ERR, - _("cannot open %s index using db%d - %s (%d)\n"), + rpmlog(RPMLOG_ERR, _("cannot open %s index using db%d - %s (%d)\n"), rpmTagGetName(rpmtag), _dbapi, (rc > 0 ? strerror(rc) : ""), rc); - _dbapi = -1; - } - - if (dbi != NULL && rc == 0) { + } else { db->_dbi[dbix] = dbi; int verifyonly = (flags & RPMDB_FLAG_VERIFYONLY); - /* Allocate for current max header instance number + some reserve */ - if (!verifyonly && rpmtag == RPMDBI_PACKAGES && db->db_bits == NULL) { - db->db_nbits = 1024 + pkgInstance(dbi, 0); - db->db_bits = PBM_ALLOC(db->db_nbits); + if (dbiType(dbi) == DBI_PRIMARY) { + /* Allocate for current max header instance number + some reserve */ + if (!verifyonly && (db->db_bits == NULL)) { + db->db_nbits = 1024 + pkgInstance(dbi, 0); + db->db_bits = PBM_ALLOC(db->db_nbits); + } } - } else { - dbi = dbiFree(dbi); } return dbi; -- 2.7.4