From a68f648cf1a1821924e08b8f99c14af9da216b10 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Fri, 22 Oct 2010 11:07:48 +0300 Subject: [PATCH] Change rpmdb internals and iterator APIs to use the appropriate tag types - The actual indexes are rpmDbiTags, and the tag passed to rpmtsInitIterator() and rpmdbInitIterator() always refers to a database index, not arbitrary header tag. The tag passed to rpmdbSetIteratorRE() however /does/ refer to a header tag. This rather important distinction can actually be expressed in the API. - As the indexes are generated from header tags of the same value, most of these need to use the TagVal types instead of actual enums to avoid mismatches - the value is what counts, not it being an enum. - Several places still have variables misleadingly named "rpmtag" when they refer to dbi tags, but leaving them for now to avoid excessive changes at once. --- lib/backend/db3.c | 2 +- lib/backend/dbconfig.c | 2 +- lib/backend/dbi.h | 8 +++---- lib/rpmdb.c | 62 +++++++++++++++++++++++++------------------------- lib/rpmdb.h | 8 +++---- lib/rpmts.c | 2 +- lib/rpmts.h | 4 ++-- 7 files changed, 44 insertions(+), 44 deletions(-) diff --git a/lib/backend/db3.c b/lib/backend/db3.c index 1b3564c..2b5d987 100644 --- a/lib/backend/db3.c +++ b/lib/backend/db3.c @@ -504,7 +504,7 @@ static int dbiFlock(dbiIndex dbi, int mode) return rc; } -int dbiOpen(rpmdb rdb, rpmTag rpmtag, dbiIndex * dbip, int flags) +int dbiOpen(rpmdb rdb, rpmDbiTagVal rpmtag, dbiIndex * dbip, int flags) { const char *dbhome = rpmdbHome(rdb); dbiIndex dbi = NULL; diff --git a/lib/backend/dbconfig.c b/lib/backend/dbconfig.c index 2f336b7..d4d87c5 100644 --- a/lib/backend/dbconfig.c +++ b/lib/backend/dbconfig.c @@ -81,7 +81,7 @@ dbiIndex dbiFree(dbiIndex dbi) return dbi; } -dbiIndex dbiNew(rpmdb rdb, rpmTag rpmtag) +dbiIndex dbiNew(rpmdb rdb, rpmDbiTagVal rpmtag) { dbiIndex dbi = xcalloc(1, sizeof(*dbi)); char *dbOpts; diff --git a/lib/backend/dbi.h b/lib/backend/dbi.h index f9b7949..e197030 100644 --- a/lib/backend/dbi.h +++ b/lib/backend/dbi.h @@ -89,11 +89,11 @@ void dbSetFSync(void *dbenv, int enable); /** \ingroup dbi * Return new configured index database handle instance. * @param rdb rpm database - * @param rpmtag rpm tag + * @param rpmtag database index tag * @return index database handle */ RPM_GNUC_INTERNAL -dbiIndex dbiNew(rpmdb rdb, rpmTag rpmtag); +dbiIndex dbiNew(rpmdb rdb, rpmDbiTagVal rpmtag); /** \ingroup dbi * Destroy index database handle instance. @@ -115,13 +115,13 @@ char * prDbiOpenFlags(int dbflags, int print_dbenv_flags); /** \ingroup dbi * Actually open the database of the index. * @param db rpm database - * @param rpmtag rpm tag + * @param rpmtag database index tag * @param dbiIndex address of index database handle * @param flags * @return 0 on success */ RPM_GNUC_INTERNAL -int dbiOpen(rpmdb rdb, rpmTag rpmtag, dbiIndex * dbip, int flags); +int dbiOpen(rpmdb rdb, rpmDbiTagVal rpmtag, dbiIndex * dbip, int flags); /* FIX: vector annotations */ diff --git a/lib/rpmdb.c b/lib/rpmdb.c index 017a9a6..199ed82 100644 --- a/lib/rpmdb.c +++ b/lib/rpmdb.c @@ -36,20 +36,20 @@ #include "lib/header_internal.h" /* XXX for headerSetInstance() */ #include "debug.h" -static rpmTag const dbiTags[] = { +static rpmDbiTag const dbiTags[] = { RPMDBI_PACKAGES, - RPMTAG_NAME, - RPMTAG_BASENAMES, - RPMTAG_GROUP, - RPMTAG_REQUIRENAME, - RPMTAG_PROVIDENAME, - RPMTAG_CONFLICTNAME, - RPMTAG_OBSOLETENAME, - RPMTAG_TRIGGERNAME, - RPMTAG_DIRNAMES, - RPMTAG_INSTALLTID, - RPMTAG_SIGMD5, - RPMTAG_SHA1HEADER, + RPMDBI_NAME, + RPMDBI_BASENAMES, + RPMDBI_GROUP, + RPMDBI_REQUIRENAME, + RPMDBI_PROVIDENAME, + RPMDBI_CONFLICTNAME, + RPMDBI_OBSOLETENAME, + RPMDBI_TRIGGERNAME, + RPMDBI_DIRNAMES, + RPMDBI_INSTALLTID, + RPMDBI_SIGMD5, + RPMDBI_SHA1HEADER, }; #define dbiTagsMax (sizeof(dbiTags) / sizeof(rpmTag)) @@ -68,7 +68,7 @@ typedef struct _dbiIndexSet { } * dbiIndexSet; static int doOpenAll(rpmdb db); -static int addToIndex(dbiIndex dbi, rpmTag rpmtag, unsigned int hdrNum, Header h); +static int addToIndex(dbiIndex dbi, rpmTagVal rpmtag, unsigned int hdrNum, Header h); static unsigned int pkgInstance(dbiIndex dbi, int alloc); static rpmdb rpmdbUnlink(rpmdb db); @@ -151,7 +151,7 @@ static int buildIndexes(rpmdb db) * @param flags * @return index database handle */ -static dbiIndex rpmdbOpenIndex(rpmdb db, rpmTag rpmtag, int flags) +static dbiIndex rpmdbOpenIndex(rpmdb db, rpmDbiTagVal rpmtag, int flags) { int dbix; dbiIndex dbi = NULL; @@ -492,7 +492,7 @@ struct rpmdbMatchIterator_s { void * mi_keyp; size_t mi_keylen; rpmdb mi_db; - rpmTag mi_rpmtag; + rpmDbiTagVal mi_rpmtag; dbiIndexSet mi_set; DBC * mi_dbc; int mi_setx; @@ -514,7 +514,7 @@ struct rpmdbKeyIterator_s { rpmdbKeyIterator ki_next; rpmdb ki_db; dbiIndex ki_dbi; - rpmTag ki_rpmtag; + rpmDbiTagVal ki_rpmtag; DBC * ki_dbc; DBT ki_key; }; @@ -887,7 +887,7 @@ static int rpmdbFindByFile(rpmdb db, const char * filespec, dbiIndex dbi = NULL; DBC * dbcursor; dbiIndexSet allMatches = NULL; - rpmTag dbtag = RPMTAG_BASENAMES; + rpmDbiTag dbtag = RPMDBI_BASENAMES; unsigned int i; int rc = -2; /* assume error */ int xx; @@ -1005,7 +1005,7 @@ int rpmdbCountPackages(rpmdb db, const char * name) DBC * dbcursor = NULL; DBT key, data; dbiIndex dbi; - rpmTag dbtag = RPMTAG_NAME; + rpmDbiTag dbtag = RPMDBI_NAME; int rc; int xx; @@ -1049,7 +1049,7 @@ int rpmdbCountPackages(rpmdb db, const char * name) /** * Attempt partial matches on name[-version[-release]] strings. * @param db rpmdb handle - * @param dbi index database handle (always RPMTAG_NAME) + * @param dbi index database handle (always RPMDBI_NAME) * @param dbcursor index database cursor * @param key search key/length/flags * @param data search data/length/flags @@ -1139,7 +1139,7 @@ exit: * Both version and release can be patterns. * @todo Name must be an exact match, as name is a db key. * @param db rpmdb handle - * @param dbi index database handle (always RPMTAG_NAME) + * @param dbi index database handle (always RPMDBI_NAME) * @param dbcursor index database cursor * @param key search key/length/flags * @param data search data/length/flags @@ -1416,7 +1416,7 @@ static int mireCmp(const void * a, const void * b) * @param pattern pattern to duplicate * @return duplicated pattern */ -static char * mireDup(rpmTag tag, rpmMireMode *modep, +static char * mireDup(rpmTagVal tag, rpmMireMode *modep, const char * pattern) { const char * s; @@ -1504,7 +1504,7 @@ static char * mireDup(rpmTag tag, rpmMireMode *modep, return pat; } -int rpmdbSetIteratorRE(rpmdbMatchIterator mi, rpmTag tag, +int rpmdbSetIteratorRE(rpmdbMatchIterator mi, rpmTagVal tag, rpmMireMode mode, const char * pattern) { static rpmMireMode defmode = (rpmMireMode)-1; @@ -2003,7 +2003,7 @@ int rpmdbAppendIterator(rpmdbMatchIterator mi, const int * hdrNums, int nHdrNums return 0; } -rpmdbMatchIterator rpmdbInitIterator(rpmdb db, rpmTag rpmtag, +rpmdbMatchIterator rpmdbInitIterator(rpmdb db, rpmDbiTagVal rpmtag, const void * keyp, size_t keylen) { rpmdbMatchIterator mi = NULL; @@ -2019,7 +2019,7 @@ rpmdbMatchIterator rpmdbInitIterator(rpmdb db, rpmTag rpmtag, /* XXX HACK to remove rpmdbFindByLabel/findMatches from the API */ if (rpmtag == RPMDBI_LABEL) { - rpmtag = RPMTAG_NAME; + rpmtag = RPMDBI_NAME; isLabel = 1; } @@ -2050,7 +2050,7 @@ rpmdbMatchIterator rpmdbInitIterator(rpmdb db, rpmTag rpmtag, rc = dbiFindByLabel(db, dbi, dbcursor, &key, &data, keyp, &set); xx = dbiCclose(dbi, dbcursor, 0); dbcursor = NULL; - } else if (rpmtag == RPMTAG_BASENAMES) { + } else if (rpmtag == RPMDBI_BASENAMES) { rc = rpmdbFindByFile(db, keyp, &key, &data, &set); } else { xx = dbiCopen(dbi, &dbcursor, 0); @@ -2228,7 +2228,7 @@ static int td2key(rpmtd tagdata, DBT *key, int *freedata) * rpmdbKeyIterator */ -rpmdbKeyIterator rpmdbKeyIteratorInit(rpmdb db, rpmTag rpmtag) +rpmdbKeyIterator rpmdbKeyIteratorInit(rpmdb db, rpmDbiTagVal rpmtag) { rpmdbKeyIterator ki; dbiIndex dbi = NULL; @@ -2421,7 +2421,7 @@ int rpmdbRemove(rpmdb db, unsigned int hdrNum) memset(&data, 0, sizeof(data)); for (int dbix = 1; dbix < dbiTagsMax; dbix++) { - rpmTag rpmtag = dbiTags[dbix]; + rpmDbiTag rpmtag = dbiTags[dbix]; int xx = 0; struct rpmtd_s tagdata; @@ -2579,7 +2579,7 @@ static unsigned int pkgInstance(dbiIndex dbi, int alloc) } /* Add data to secondary index */ -static int addToIndex(dbiIndex dbi, rpmTag rpmtag, unsigned int hdrNum, Header h) +static int addToIndex(dbiIndex dbi, rpmTagVal rpmtag, unsigned int hdrNum, Header h) { int xx, i, rc = 0; struct rpmtd_s tagdata, reqflags; @@ -2733,7 +2733,7 @@ int rpmdbAdd(rpmdb db, Header h) /* Add associated data to secondary indexes */ if (ret == 0) { for (int dbix = 1; dbix < dbiTagsMax; dbix++) { - rpmTag rpmtag = dbiTags[dbix]; + rpmDbiTag rpmtag = dbiTags[dbix]; if (!(dbi = rpmdbOpenIndex(db, rpmtag, 0))) continue; @@ -2827,7 +2827,7 @@ static int rpmdbMoveDatabase(const char * prefix, /* Fall through */ case 3: for (i = 0; i < dbiTagsMax; i++) { - rpmTag rpmtag = dbiTags[i]; + rpmDbiTag rpmtag = dbiTags[i]; const char *base = rpmTagGetName(rpmtag); char *src = rpmGetPath(prefix, "/", olddbpath, "/", base, NULL); char *dest = rpmGetPath(prefix, "/", newdbpath, "/", base, NULL); diff --git a/lib/rpmdb.h b/lib/rpmdb.h index ee5ebf7..0473a83 100644 --- a/lib/rpmdb.h +++ b/lib/rpmdb.h @@ -136,7 +136,7 @@ int rpmdbAppendIterator(rpmdbMatchIterator mi, * @param pattern pattern to match * @return 0 on success */ -int rpmdbSetIteratorRE(rpmdbMatchIterator mi, rpmTag tag, +int rpmdbSetIteratorRE(rpmdbMatchIterator mi, rpmTagVal tag, rpmMireMode mode, const char * pattern); /** \ingroup rpmdb @@ -169,12 +169,12 @@ int rpmdbSetHdrChk(rpmdbMatchIterator mi, rpmts ts, /** \ingroup rpmdb * Return database iterator. * @param db rpm database - * @param rpmtag rpm tag + * @param rpmtag database index tag * @param keyp key data (NULL for sequential access) * @param keylen key data length (0 will use strlen(keyp)) * @return NULL on failure */ -rpmdbMatchIterator rpmdbInitIterator(rpmdb db, rpmTag rpmtag, +rpmdbMatchIterator rpmdbInitIterator(rpmdb db, rpmDbiTagVal rpmtag, const void * keyp, size_t keylen); /** \ingroup rpmdb @@ -225,7 +225,7 @@ int rpmdbRebuild(const char * prefix, rpmts ts, * @param rpmtag the index to iterate over * @return the key iterator */ -rpmdbKeyIterator rpmdbKeyIteratorInit(rpmdb db, rpmTag rpmtag); +rpmdbKeyIterator rpmdbKeyIteratorInit(rpmdb db, rpmDbiTagVal rpmtag); /** \ingroup rpmdb * Get the next key - must be called before getting the first key diff --git a/lib/rpmts.c b/lib/rpmts.c index c6c846f..e6d5d08 100644 --- a/lib/rpmts.c +++ b/lib/rpmts.c @@ -148,7 +148,7 @@ int rpmtsVerifyDB(rpmts ts) } /* keyp might no be defined. */ -rpmdbMatchIterator rpmtsInitIterator(const rpmts ts, rpmTag rpmtag, +rpmdbMatchIterator rpmtsInitIterator(const rpmts ts, rpmDbiTagVal rpmtag, const void * keyp, size_t keylen) { rpmdbMatchIterator mi = NULL; diff --git a/lib/rpmts.h b/lib/rpmts.h index fbf9a06..ab0477e 100644 --- a/lib/rpmts.h +++ b/lib/rpmts.h @@ -263,12 +263,12 @@ int rpmtsVerifyDB(rpmts ts); /** \ingroup rpmts * Return transaction database iterator. * @param ts transaction set - * @param rpmtag rpm tag + * @param rpmtag database index tag * @param keyp key data (NULL for sequential access) * @param keylen key data length (0 will use strlen(keyp)) * @return NULL on failure */ -rpmdbMatchIterator rpmtsInitIterator(const rpmts ts, rpmTag rpmtag, +rpmdbMatchIterator rpmtsInitIterator(const rpmts ts, rpmDbiTagVal rpmtag, const void * keyp, size_t keylen); /** \ingroup rpmts -- 2.7.4