size_t alloced; /*!< alloced size */
} * dbiIndexSet;
+static int doOpenAll(rpmdb db);
+static int addToIndex(dbiIndex dbi, rpmTag rpmtag, unsigned int hdrNum, Header h);
static unsigned int pkgInstance(dbiIndex dbi, int alloc);
static rpmdb rpmdbUnlink(rpmdb db);
return *sp;
}
+static int buildIndexes(rpmdb db)
+{
+ int rc = 0;
+ Header h;
+ rpmdbMatchIterator mi;
+
+ rc += doOpenAll(db);
+
+ /* If the main db was just created, this is expected - dont whine */
+ if (!(db->_dbi[0]->dbi_oflags & DB_CREATE)) {
+ rpmlog(RPMLOG_WARNING,
+ _("Generating %d missing index(es), please wait...\n"),
+ db->db_buildindex);
+ }
+
+ /* Don't call us again */
+ db->db_buildindex = 0;
+
+ mi = rpmdbInitIterator(db, RPMDBI_PACKAGES, NULL, 0);
+ while ((h = rpmdbNextIterator(mi))) {
+ unsigned int hdrNum = headerGetInstance(h);
+ /* Build all secondary indexes which were created on open */
+ for (int dbix = 1; dbix < dbiTagsMax; dbix++) {
+ dbiIndex dbi = db->_dbi[dbix];
+ if (dbi && (dbi->dbi_oflags & DB_CREATE)) {
+ rc += addToIndex(dbi, dbiTags[dbix], hdrNum, h);
+ }
+ }
+ }
+ rpmdbFreeIterator(mi);
+
+ return rc;
+}
+
/** \ingroup dbi
* Return handle for an index database.
* @param db rpm database
return dbdir;
}
+static int doOpenAll(rpmdb db)
+{
+ int rc = 0;
+ for (int dbix = 0; dbix < dbiTagsMax; dbix++) {
+ dbiIndex dbi = db->_dbi[dbix];
+ if (dbi == NULL) {
+ rc += (rpmdbOpenIndex(db, dbiTags[dbix], db->db_flags) == NULL);
+ }
+ }
+ return rc;
+}
+
int rpmdbOpenAll(rpmdb db)
{
int rc = 0;
if (db == NULL) return -2;
- for (int dbix = 0; dbix < dbiTagsMax; dbix++) {
- if (db->_dbi[dbix] != NULL)
- continue;
- (void) rpmdbOpenIndex(db, dbiTags[dbix], db->db_flags);
+ rc += doOpenAll(db);
+
+ if (db->db_buildindex) {
+ rc += buildIndexes(db);
}
return rc;
}
if (dbi == NULL)
return NULL;
+ if (db->db_buildindex)
+ buildIndexes(db);
+
/*
* Handle label and file name special cases.
* Otherwise, retrieve join keys for secondary lookup.