diff options
author | jbj <devnull@localhost> | 2000-04-12 13:42:57 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 2000-04-12 13:42:57 +0000 |
commit | f3571adf59bc99f660fae74353fcd8b6b9da2882 (patch) | |
tree | 3eb320df4b9b254ffb6fd5303cec09807984702b /lib | |
parent | 3cbb3be0452b4eddfec2dfc8ca1da2ede59eb9b0 (diff) | |
download | librpm-tizen-f3571adf59bc99f660fae74353fcd8b6b9da2882.tar.gz librpm-tizen-f3571adf59bc99f660fae74353fcd8b6b9da2882.tar.bz2 librpm-tizen-f3571adf59bc99f660fae74353fcd8b6b9da2882.zip |
API: pass *SearchIndex() length of key (0 will use strlen(key)).
API: remove rpmdb{First,Next}RecNum routines.
db3.c: remove cursor DB_RMW implementation, something else is needed.
rpmdb.c: first crack at rpmdb match iterator.
query.c: ditto.
rebuilddb.c: ditto.
dumpdb.c: ditto.
CVS patchset: 3668
CVS date: 2000/04/12 13:42:57
Diffstat (limited to 'lib')
-rw-r--r-- | lib/db0.c | 7 | ||||
-rw-r--r-- | lib/db1.c | 7 | ||||
-rw-r--r-- | lib/db2.c | 6 | ||||
-rw-r--r-- | lib/db3.c | 39 | ||||
-rw-r--r-- | lib/dbindex.c | 6 | ||||
-rw-r--r-- | lib/dbindex.h | 4 | ||||
-rw-r--r-- | lib/query.c | 102 | ||||
-rw-r--r-- | lib/rebuilddb.c | 81 | ||||
-rw-r--r-- | lib/rpmdb.c | 162 | ||||
-rw-r--r-- | lib/rpmlib.h | 38 |
10 files changed, 356 insertions, 96 deletions
@@ -118,17 +118,20 @@ static int db0sync(dbiIndex dbi, unsigned int flags) { return rc; } -static int db0SearchIndex(dbiIndex dbi, const char * str, dbiIndexSet * set) { +static int db0SearchIndex(dbiIndex dbi, const char * str, size_t len, + dbiIndexSet * set) +{ DBT key, data; DB * db = GetDB(dbi); int rc; if (set) *set = NULL; + if (len == 0) len = strlen(str); _mymemset(&key, 0, sizeof(key)); _mymemset(&data, 0, sizeof(data)); key.data = (void *)str; - key.size = strlen(str); + key.size = len; data.data = NULL; data.size = 0; @@ -116,17 +116,20 @@ static int db1sync(dbiIndex dbi, unsigned int flags) { return rc; } -static int db1SearchIndex(dbiIndex dbi, const char * str, dbiIndexSet * set) { +static int db1SearchIndex(dbiIndex dbi, const char * str, size_t len, + dbiIndexSet * set) +{ DBT key, data; DB * db = GetDB(dbi); int rc; if (set) *set = NULL; + if (len == 0) len = strlen(str); _mymemset(&key, 0, sizeof(key)); _mymemset(&data, 0, sizeof(data)); key.data = (void *)str; - key.size = strlen(str); + key.size = len; data.data = NULL; data.size = 0; @@ -247,7 +247,8 @@ static int db2sync(dbiIndex dbi, unsigned int flags) return rc; } -static int db2SearchIndex(dbiIndex dbi, const char * str, dbiIndexSet * set) +static int db2SearchIndex(dbiIndex dbi, const char * str, size_t len, + dbiIndexSet * set) { DBT key, data; DB * db = GetDB(dbi); @@ -255,11 +256,12 @@ static int db2SearchIndex(dbiIndex dbi, const char * str, dbiIndexSet * set) int rc; if (set) *set = NULL; + if (len == 0) len = strlen(str); _mymemset(&key, 0, sizeof(key)); _mymemset(&data, 0, sizeof(data)); key.data = (void *)str; - key.size = strlen(str); + key.size = len; data.data = NULL; data.size = 0; @@ -390,7 +390,8 @@ union _dbswap { _b = _c[2]; _c[2] = _c[1]; _c[1] = _b; \ } -static int db3SearchIndex(dbiIndex dbi, const char * str, dbiIndexSet * set) +static int db3SearchIndex(dbiIndex dbi, const char * str, size_t len, + dbiIndexSet * set) { DBT key, data; DB * db = GetDB(dbi); @@ -398,21 +399,16 @@ static int db3SearchIndex(dbiIndex dbi, const char * str, dbiIndexSet * set) int rc; if (set) *set = NULL; + if (len == 0) len = strlen(str); _mymemset(&key, 0, sizeof(key)); _mymemset(&data, 0, sizeof(data)); key.data = (void *)str; - key.size = strlen(str); + key.size = len; data.data = NULL; data.size = 0; #if defined(__USE_DB2) || defined(__USE_DB3) -#if defined(__USE_DB3) - if (dbi->dbi_dbcursor) { - DBC *dbcursor = dbi->dbi_dbcursor; - rc = dbcursor->c_get(dbcursor, &key, &data, DB_SET); /* DB_RMW */ - } else -#endif rc = db->get(db, NULL, &key, &data, 0); _printit = (rc == DB_NOTFOUND ? 0 : _debug); rc = cvtdberr(dbi, "db->get", rc, _printit); @@ -485,20 +481,6 @@ static int db3UpdateIndex(dbiIndex dbi, const char * str, dbiIndexSet set) dbir[i].fileNumber = fileNumber.ui; } -#if defined(__USE_DB3) - if (dbi->dbi_dbcursor) { - DBC *dbcursor = dbi->dbi_dbcursor; - int xx; - - rc = dbcursor->c_get(dbcursor, &key, &data, (DB_SET|DB_RMW)); - xx = cvtdberr(dbi, "db->c_get RMW put", rc, _debug); - data.data = dbir; - data.size = set->count * sizeof(*dbir); - rc = dbcursor->c_put(dbcursor, &key, &data, - (rc == DB_NOTFOUND ? DB_KEYFIRST : DB_CURRENT)); - rc = cvtdberr(dbi, "db->c_put RMW", rc, _debug); - } else -#endif { data.data = dbir; data.size = set->count * sizeof(*dbir); @@ -512,19 +494,6 @@ static int db3UpdateIndex(dbiIndex dbi, const char * str, dbiIndexSet set) } else { #if defined(__USE_DB2) || defined(__USE_DB3) -#if defined(__USE_DB3) - if (dbi->dbi_dbcursor) { - DBC *dbcursor = dbi->dbi_dbcursor; - int xx; - - rc = dbcursor->c_get(dbcursor, &key, &data, (DB_SET|DB_RMW)); - xx = cvtdberr(dbi, "db->c_get RMW del", rc, _debug); - if (rc != DB_NOTFOUND) { - rc = dbcursor->c_del(dbcursor, 0); - rc = cvtdberr(dbi, "db->c_del RMW", rc, _debug); - } - } else -#endif { rc = db->del(db, NULL, &key, 0); rc = cvtdberr(dbi, "db->del", rc, _debug); diff --git a/lib/dbindex.c b/lib/dbindex.c index 730ded8ec..7ea7dcf1a 100644 --- a/lib/dbindex.c +++ b/lib/dbindex.c @@ -197,10 +197,12 @@ int dbiFreeCursor(dbiIndex dbi) { return rc; } -int dbiSearchIndex(dbiIndex dbi, const char * str, dbiIndexSet * set) { +int dbiSearchIndex(dbiIndex dbi, const char * str, size_t len, + dbiIndexSet * set) +{ int rc; - rc = (*dbi->dbi_vec->SearchIndex) (dbi, str, set); + rc = (*dbi->dbi_vec->SearchIndex) (dbi, str, len, set); switch (rc) { case -1: diff --git a/lib/dbindex.h b/lib/dbindex.h index 60c1a61dc..3f053bdc6 100644 --- a/lib/dbindex.h +++ b/lib/dbindex.h @@ -77,7 +77,7 @@ struct _dbiVec { * @param set items retrieved from index database * @return -1 error, 0 success, 1 not found */ - int (*SearchIndex) (dbiIndex dbi, const char * str, dbiIndexSet * set); + int (*SearchIndex) (dbiIndex dbi, const void * str, size_t len, dbiIndexSet * set); /** * Change/delete items that match criteria. @@ -199,7 +199,7 @@ int dbiSyncIndex(dbiIndex dbi); * @param set items retrieved from index database * @return -1 error, 0 success, 1 not found */ -int dbiSearchIndex(dbiIndex dbi, const char * str, /*@out@*/ dbiIndexSet * set); +int dbiSearchIndex(dbiIndex dbi, const char * str, size_t len, /*@out@*/ dbiIndexSet * set); /** * Change/delete items that match criteria. diff --git a/lib/query.c b/lib/query.c index 69da3fbd6..920f7de08 100644 --- a/lib/query.c +++ b/lib/query.c @@ -418,6 +418,20 @@ void rpmDisplayQueryTags(FILE * f) } } +int XshowMatches(QVA_t *qva, rpmdbMatchIterator mi, QVF_t showPackage) +{ + Header h; + int ec = 0; + + while ((h = rpmdbNextIterator(mi)) != NULL) { + int rc; + if ((rc = showPackage(qva, NULL, h)) != 0) + ec = rc; + } + rpmdbFreeIterator(mi); + return ec; +} + int showMatches(QVA_t *qva, rpmdb db, dbiIndexSet matches, QVF_t showPackage) { Header h; @@ -455,9 +469,9 @@ void (*freeSpecVec) (Spec spec) = NULL; int rpmQueryVerify(QVA_t *qva, enum rpmQVSources source, const char * arg, rpmdb db, QVF_t showPackage) { - dbiIndexSet matches = NULL; + dbiIndexSet matches = NULL; /* XXX DYING */ + rpmdbMatchIterator mi = NULL; Header h; - int offset; int rc; int isSource; int recNumber; @@ -562,6 +576,8 @@ int rpmQueryVerify(QVA_t *qva, enum rpmQVSources source, const char * arg, } break; case RPMQV_ALL: +#ifdef DYING + { unsigned int offset; for (offset = rpmdbFirstRecNum(db); offset != 0; offset = rpmdbNextRecNum(db, offset)) { @@ -574,47 +590,98 @@ int rpmQueryVerify(QVA_t *qva, enum rpmQVSources source, const char * arg, retcode = rc; headerFree(h); } + } +#else + mi = rpmdbInitIterator(db, RPMDBI_PACKAGES, NULL, 0); + if (mi == NULL) { + fprintf(stderr, _("no packages\n")); + retcode = 1; + } else { + retcode = XshowMatches(qva, mi, showPackage); + } +#endif break; case RPMQV_GROUP: +#ifdef DYING if (rpmdbFindByGroup(db, arg, &matches)) { fprintf(stderr, _("group %s does not contain any packages\n"), arg); retcode = 1; } else { retcode = showMatches(qva, db, matches, showPackage); } +#else + mi = rpmdbInitIterator(db, RPMDBI_GROUP, arg, 0); + if (mi == NULL) { + fprintf(stderr, _("group %s does not contain any packages\n"), arg); + retcode = 1; + } else { + retcode = XshowMatches(qva, mi, showPackage); + } +#endif break; case RPMQV_TRIGGEREDBY: +#ifdef DYING if (rpmdbFindByTriggeredBy(db, arg, &matches)) { fprintf(stderr, _("no package triggers %s\n"), arg); retcode = 1; } else { retcode = showMatches(qva, db, matches, showPackage); } +#else + mi = rpmdbInitIterator(db, RPMDBI_TRIGGER, arg, 0); + if (mi == NULL) { + fprintf(stderr, _("no package triggers %s\n"), arg); + retcode = 1; + } else { + retcode = XshowMatches(qva, mi, showPackage); + } +#endif /* DYING */ break; case RPMQV_WHATREQUIRES: +#ifdef DYING if (rpmdbFindByRequiredBy(db, arg, &matches)) { fprintf(stderr, _("no package requires %s\n"), arg); retcode = 1; } else { retcode = showMatches(qva, db, matches, showPackage); } +#else + mi = rpmdbInitIterator(db, RPMDBI_REQUIREDBY, arg, 0); + if (mi == NULL) { + fprintf(stderr, _("no package requires %s\n"), arg); + retcode = 1; + } else { + retcode = XshowMatches(qva, mi, showPackage); + } +#endif /* DYING */ break; case RPMQV_WHATPROVIDES: if (arg[0] != '/') { +#ifdef DYING if (rpmdbFindByProvides(db, arg, &matches)) { fprintf(stderr, _("no package provides %s\n"), arg); retcode = 1; } else { retcode = showMatches(qva, db, matches, showPackage); } +#else + mi = rpmdbInitIterator(db, RPMDBI_PROVIDES, arg, 0); + if (mi == NULL) { + fprintf(stderr, _("no package provides %s\n"), arg); + retcode = 1; + } else { + retcode = XshowMatches(qva, mi, showPackage); + } +#endif /* DYING */ break; } /*@fallthrough@*/ case RPMQV_PATH: +#ifdef DYING if (rpmdbFindByFile(db, arg, &matches)) { int myerrno = 0; if (access(arg, F_OK) != 0) @@ -631,6 +698,25 @@ int rpmQueryVerify(QVA_t *qva, enum rpmQVSources source, const char * arg, } else { retcode = showMatches(qva, db, matches, showPackage); } +#else + mi = rpmdbInitIterator(db, RPMDBI_FILE, arg, 0); + if (mi == NULL) { + int myerrno = 0; + if (access(arg, F_OK) != 0) + myerrno = errno; + switch (myerrno) { + default: + fprintf(stderr, _("file %s: %s\n"), arg, strerror(myerrno)); + break; + case 0: + fprintf(stderr, _("file %s is not owned by any package\n"), arg); + break; + } + retcode = 1; + } else { + retcode = XshowMatches(qva, mi, showPackage); + } +#endif /* DYING */ break; case RPMQV_DBOFFSET: @@ -650,6 +736,7 @@ int rpmQueryVerify(QVA_t *qva, enum rpmQVSources source, const char * arg, return 1; } rpmMessage(RPMMESS_DEBUG, _("package record number: %d\n"), recNumber); +#ifdef DYING h = rpmdbGetRecord(db, recNumber); if (h == NULL) { fprintf(stderr, _("record %d could not be read\n"), recNumber); @@ -658,6 +745,15 @@ int rpmQueryVerify(QVA_t *qva, enum rpmQVSources source, const char * arg, retcode = showPackage(qva, db, h); headerFree(h); } +#else + mi = rpmdbInitIterator(db, RPMDBI_PACKAGES, &recNumber, sizeof(recNumber)); + if (mi == NULL) { + fprintf(stderr, _("record %d could not be read\n"), recNumber); + retcode = 1; + } else { + retcode = XshowMatches(qva, mi, showPackage); + } +#endif } break; case RPMQV_PACKAGE: @@ -674,7 +770,7 @@ int rpmQueryVerify(QVA_t *qva, enum rpmQVSources source, const char * arg, break; } - if (matches) { + if (matches) { /* XXX DYING */ dbiFreeIndexSet(matches); matches = NULL; } diff --git a/lib/rebuilddb.c b/lib/rebuilddb.c index 7b7b43145..610d721bb 100644 --- a/lib/rebuilddb.c +++ b/lib/rebuilddb.c @@ -11,18 +11,17 @@ extern int __do_dbenv_remove; /* XXX in dbindex.c, shared with rebuilddb.c */ /** */ int rpmdbRebuild(const char * rootdir) { - rpmdb olddb, newdb; + rpmdb olddb; const char * dbpath = NULL; const char * rootdbpath = NULL; + rpmdb newdb; const char * newdbpath = NULL; const char * newrootdbpath = NULL; const char * tfn; - int recnum; - Header h; int nocleanup = 1; int failed = 0; int rc = 0; - int _filterDbDups; /* XXX always eliminate duplicate entries */ + int _filterDbDups; /* Filter duplicate entries ? (bug in pre rpm-3.0.4) */ int _preferDbiMajor; _filterDbDups = rpmExpandNumeric("%{_filterdbdups}"); @@ -95,24 +94,51 @@ fprintf(stderr, "*** rpmdbRebuild: filterdbdups %d preferdb %d\n", _filterDbDups goto exit; } - recnum = rpmdbFirstRecNum(olddb); - while (recnum > 0) { - if ((h = rpmdbGetRecord(olddb, recnum)) == NULL) { - rpmError(RPMERR_INTERNAL, + { Header h = NULL; + +#ifdef DYING + int recnum; +#define _RECNUM recnum + for (recnum = rpmdbFirstRecNum(olddb); + recnum > 0; + recnum = rpmdbNextRecNum(olddb, recnum)) + { + if (h) { + headerFree(h); + h = NULL; + } + if ((h = rpmdbGetRecord(olddb, recnum)) == NULL) { + rpmError(RPMERR_INTERNAL, _("record number %d in database is bad -- skipping it"), recnum); - break; - } else { + continue; + } +#else + rpmdbMatchIterator mi; +#define _RECNUM rpmdbGetIteratorOffset(mi) + + mi = rpmdbInitIterator(olddb, RPMDBI_PACKAGES, NULL, 0); + while ((h = rpmdbNextIterator(mi)) != NULL) { +#endif + /* let's sanity check this record a bit, otherwise just skip it */ - if (headerIsEntry(h, RPMTAG_NAME) && + if (!(headerIsEntry(h, RPMTAG_NAME) && headerIsEntry(h, RPMTAG_VERSION) && headerIsEntry(h, RPMTAG_RELEASE) && - headerIsEntry(h, RPMTAG_BUILDTIME)) { + headerIsEntry(h, RPMTAG_BUILDTIME))) + { + rpmError(RPMERR_INTERNAL, + _("record number %d in database is bad -- skipping."), + _RECNUM); + continue; + } + + /* Filter duplicate entries ? (bug in pre rpm-3.0.4) */ + if (_filterDbDups) { dbiIndexSet matches = NULL; int skip; - /* XXX always eliminate duplicate entries */ - if (_filterDbDups && !rpmdbFindByHeader(newdb, h, &matches)) { + if (!rpmdbFindByHeader(newdb, h, &matches)) { const char * name, * version, * release; headerNVR(h, &name, &version, &release); @@ -127,21 +153,28 @@ fprintf(stderr, "*** rpmdbRebuild: filterdbdups %d preferdb %d\n", _filterDbDups matches = NULL; } - if (skip == 0 && rpmdbAdd(newdb, h)) { - rpmError(RPMERR_INTERNAL, - _("cannot add record originally at %d"), recnum); - failed = 1; - break; - } - } else { + if (skip) + continue; + } + + if (rpmdbAdd(newdb, h)) { rpmError(RPMERR_INTERNAL, - _("record number %d in database is bad -- skipping."), - recnum); + _("cannot add record originally at %d"), _RECNUM); + failed = 1; + break; } +#ifndef DYING + } + rpmdbFreeIterator(mi); +#else + } + if (h) { headerFree(h); + h = NULL; } - recnum = rpmdbNextRecNum(olddb, recnum); +#endif + } if (!nocleanup) diff --git a/lib/rpmdb.c b/lib/rpmdb.c index 28f2af0ca..34ff33c23 100644 --- a/lib/rpmdb.c +++ b/lib/rpmdb.c @@ -11,6 +11,7 @@ #include "dbindex.h" /*@access dbiIndexSet@*/ /*@access dbiIndexRecord@*/ +/*@access rpmdbMatchIterator@*/ #include "falloc.h" #include "fprint.h" @@ -28,35 +29,27 @@ struct _dbiIndex rpmdbi[] = { { "packages.rpm", 0, DBI_HASH, _DBI_FLAGS, _DBI_PERMS, _DBI_MAJOR, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, -#define RPMDBI_PACKAGES 0 { "nameindex.rpm", RPMTAG_NAME, DBI_HASH, _DBI_FLAGS, _DBI_PERMS, _DBI_MAJOR, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, -#define RPMDBI_NAME 1 { "fileindex.rpm", RPMTAG_BASENAMES, DBI_HASH, _DBI_FLAGS, _DBI_PERMS, _DBI_MAJOR, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, -#define RPMDBI_FILE 2 { "groupindex.rpm", RPMTAG_GROUP, DBI_HASH, _DBI_FLAGS, _DBI_PERMS, _DBI_MAJOR, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, -#define RPMDBI_GROUP 3 { "requiredby.rpm", RPMTAG_REQUIRENAME, DBI_HASH, _DBI_FLAGS, _DBI_PERMS, _DBI_MAJOR, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, -#define RPMDBI_REQUIREDBY 4 { "providesindex.rpm", RPMTAG_PROVIDENAME, DBI_HASH, _DBI_FLAGS, _DBI_PERMS, _DBI_MAJOR, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, -#define RPMDBI_PROVIDES 5 { "conflictsindex.rpm", RPMTAG_CONFLICTNAME, DBI_HASH, _DBI_FLAGS, _DBI_PERMS, _DBI_MAJOR, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, -#define RPMDBI_CONFLICTS 6 { "triggerindex.rpm", RPMTAG_TRIGGERNAME, DBI_HASH, _DBI_FLAGS, _DBI_PERMS, _DBI_MAJOR, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }, -#define RPMDBI_TRIGGER 7 { NULL } #define RPMDBI_MIN 0 #define RPMDBI_MAX 8 @@ -263,6 +256,7 @@ void rpmdbClose (rpmdb db) free(db); } +#ifdef DYING int rpmdbFirstRecNum(rpmdb db) { dbiIndex dbi = db->_dbi[RPMDBI_PACKAGES]; unsigned int offset = 0; @@ -293,6 +287,7 @@ int rpmdbNextRecNum(rpmdb db, unsigned int lastOffset) { memcpy(&lastOffset, keyp, sizeof(lastOffset)); return lastOffset; } +#endif /* DYING */ Header rpmdbGetRecord(rpmdb db, unsigned int offset) { @@ -338,7 +333,7 @@ int rpmdbFindByFile(rpmdb db, const char * filespec, dbiIndexSet * matches) fpc = fpCacheCreate(20); fp1 = fpLookup(fpc, dirName, baseName, 1); - rc = dbiSearchIndex(db->_dbi[RPMDBI_FILE], baseName, &allMatches); + rc = dbiSearchIndex(db->_dbi[RPMDBI_FILE], baseName, 0, &allMatches); if (rc) { dbiFreeIndexSet(allMatches); allMatches = NULL; @@ -411,27 +406,27 @@ int rpmdbFindByFile(rpmdb db, const char * filespec, dbiIndexSet * matches) } int rpmdbFindByProvides(rpmdb db, const char * filespec, dbiIndexSet * matches) { - return dbiSearchIndex(db->_dbi[RPMDBI_PROVIDES], filespec, matches); + return dbiSearchIndex(db->_dbi[RPMDBI_PROVIDES], filespec, 0, matches); } int rpmdbFindByRequiredBy(rpmdb db, const char * filespec, dbiIndexSet * matches) { - return dbiSearchIndex(db->_dbi[RPMDBI_REQUIREDBY], filespec, matches); + return dbiSearchIndex(db->_dbi[RPMDBI_REQUIREDBY], filespec, 0, matches); } int rpmdbFindByConflicts(rpmdb db, const char * filespec, dbiIndexSet * matches) { - return dbiSearchIndex(db->_dbi[RPMDBI_CONFLICTS], filespec, matches); + return dbiSearchIndex(db->_dbi[RPMDBI_CONFLICTS], filespec, 0, matches); } int rpmdbFindByTriggeredBy(rpmdb db, const char * filespec, dbiIndexSet * matches) { - return dbiSearchIndex(db->_dbi[RPMDBI_TRIGGER], filespec, matches); + return dbiSearchIndex(db->_dbi[RPMDBI_TRIGGER], filespec, 0, matches); } int rpmdbFindByGroup(rpmdb db, const char * group, dbiIndexSet * matches) { - return dbiSearchIndex(db->_dbi[RPMDBI_GROUP], group, matches); + return dbiSearchIndex(db->_dbi[RPMDBI_GROUP], group, 0, matches); } int rpmdbFindPackage(rpmdb db, const char * name, dbiIndexSet * matches) { - return dbiSearchIndex(db->_dbi[RPMDBI_NAME], name, matches); + return dbiSearchIndex(db->_dbi[RPMDBI_NAME], name, 0, matches); } int rpmdbCountPackages(rpmdb db, const char * name) @@ -439,7 +434,7 @@ int rpmdbCountPackages(rpmdb db, const char * name) dbiIndexSet matches = NULL; int rc; - rc = dbiSearchIndex(db->_dbi[RPMDBI_NAME], name, &matches); + rc = dbiSearchIndex(db->_dbi[RPMDBI_NAME], name, 0, &matches); switch (rc) { default: @@ -462,13 +457,140 @@ int rpmdbCountPackages(rpmdb db, const char * name) return rc; } +struct _rpmdbMatchIterator { + const void * mi_key; + size_t mi_keylen; + rpmdb mi_db; + dbiIndex mi_dbi; + int mi_dbix; + dbiIndexSet mi_set; + int mi_setx; + Header mi_h; + unsigned int mi_offset; +}; + +void rpmdbFreeIterator(rpmdbMatchIterator mi) +{ + if (mi->mi_h) { + headerFree(mi->mi_h); + mi->mi_h = NULL; + } + if (mi->mi_set) { + dbiFreeIndexSet(mi->mi_set); + mi->mi_set = NULL; + } else { + dbiIndex dbi = mi->mi_db->_dbi[RPMDBI_PACKAGES]; + (void) (*dbi->dbi_vec->cclose) (dbi); + } + if (mi->mi_key) { + xfree(mi->mi_key); + mi->mi_key = NULL; + } + free(mi); +} + +unsigned int rpmdbGetIteratorOffset(rpmdbMatchIterator mi) { + return mi->mi_offset; +} + +Header rpmdbNextIterator(rpmdbMatchIterator mi) +{ + dbiIndex dbi = mi->mi_db->_dbi[RPMDBI_PACKAGES]; + void * uh; + size_t uhlen; + void * keyp = &mi->mi_offset; + size_t keylen = sizeof(mi->mi_offset); + int rc; + + if (mi == NULL) + return NULL; + + /* XXX skip over instances with 0 join key */ + do { + if (mi->mi_set) { + if (!(mi->mi_setx < mi->mi_set->count)) + return NULL; + mi->mi_offset = dbiIndexRecordOffset(mi->mi_set, mi->mi_setx); + mi->mi_setx++; + } else { + rc = (*dbi->dbi_vec->cget) (dbi, &keyp, &keylen, NULL, NULL); + if (rc) + return NULL; + memcpy(&mi->mi_offset, keyp, sizeof(mi->mi_offset)); + } + } while (mi->mi_offset == 0); + + /* Retrieve header */ + rc = (*dbi->dbi_vec->get) (dbi, keyp, keylen, &uh, &uhlen); + if (rc) + return NULL; + + if (mi->mi_h) { + headerFree(mi->mi_h); + mi->mi_h = NULL; + } + mi->mi_h = headerLoad(uh); + + return mi->mi_h; +} + +rpmdbMatchIterator rpmdbInitIterator(rpmdb db, int dbix, const void * key, size_t keylen) +{ + rpmdbMatchIterator mi; + dbiIndex dbi = NULL; + dbiIndexSet set = NULL; + + dbi = db->_dbi[dbix]; + + if (key) { + int rc; + rc = dbiSearchIndex(dbi, key, keylen, &set); + switch (rc) { + default: + case -1: /* error */ + case 1: /* not found */ + if (set) + dbiFreeIndexSet(set); + return NULL; + /*@notreached@*/ break; + case 0: /* success */ + break; + } + } + + mi = xcalloc(sizeof(*mi), 1); + if (key) { + if (keylen == 0) + keylen = strlen(key); + + { char * k = xmalloc(keylen + 1); + memcpy(k, key, keylen); + k[keylen] = '\0'; /* XXX for strings */ + mi->mi_key = k; + } + + mi->mi_keylen = keylen; + } else { + mi->mi_key = NULL; + mi->mi_keylen = 0; + } + mi->mi_db = db; + mi->mi_dbi = dbi; + mi->mi_dbix = dbix; + mi->mi_set = set; + mi->mi_setx = 0; + mi->mi_h = NULL; + mi->mi_offset = 0; + return mi; +} + static void removeIndexEntry(dbiIndex dbi, const char * key, dbiIndexRecord rec, int tolerant, const char * idxName) { dbiIndexSet matches = NULL; int rc; - rc = dbiSearchIndex(dbi, key, &matches); + rc = dbiSearchIndex(dbi, key, 0, &matches); switch (rc) { case 0: if (dbiRemoveIndexRecord(matches, rec)) { @@ -596,7 +718,7 @@ static int addIndexEntry(dbiIndex dbi, const char *index, dbiIndexRecord rec) dbiIndexSet set = NULL; int rc; - rc = dbiSearchIndex(dbi, index, &set); + rc = dbiSearchIndex(dbi, index, 0, &set); switch (rc) { case -1: /* error */ @@ -967,7 +1089,9 @@ int rpmdbFindFpList(rpmdb db, fingerPrint * fpList, dbiIndexSet * matchList, /* Gather all matches from the database */ for (i = 0; i < numItems; i++) { dbiIndexSet matches = NULL; - switch (dbiSearchIndex(db->_dbi[RPMDBI_FILE], fpList[i].baseName, &matches)) { + int rc; + rc = dbiSearchIndex(db->_dbi[RPMDBI_FILE], fpList[i].baseName, 0, &matches); + switch (rc) { default: break; case 2: diff --git a/lib/rpmlib.h b/lib/rpmlib.h index ba5843e60..ee9ff6867 100644 --- a/lib/rpmlib.h +++ b/lib/rpmlib.h @@ -9,11 +9,6 @@ #include <header.h> #include <popt.h> -#if DEAD -typedef /*@abstract@*/ struct _dbiIndexRecord * dbiIndexRecord; -typedef /*@abstract@*/ struct _dbiIndex * dbiIndex; -#endif - typedef /*@abstract@*/ struct _dbiIndexSet * dbiIndexSet; #ifdef __cplusplus @@ -383,6 +378,7 @@ void rpmdbClose ( /*@only@*/ rpmdb db); */ int rpmdbOpenForTraversal(const char * prefix, /*@out@*/ rpmdb * dbp); +#ifdef DYING /** * @param db rpm database */ @@ -392,6 +388,7 @@ int rpmdbFirstRecNum(rpmdb db); * @return 0 at end, -1 on error */ int rpmdbNextRecNum(rpmdb db, unsigned int lastOffset); +#endif /** * @param db rpm database @@ -444,6 +441,7 @@ int rpmdbFindByLabel(rpmdb db, const char * label, */ int rpmdbFindByHeader(rpmdb db, Header h, /*@out@*/ dbiIndexSet * matches); + /** * Return number of instances of package in rpm database. * @param db rpm database @@ -452,6 +450,35 @@ int rpmdbFindByHeader(rpmdb db, Header h, */ int rpmdbCountPackages(rpmdb db, const char *name); +/** + */ +typedef /*@abstract@*/ struct _rpmdbMatchIterator * rpmdbMatchIterator; + +/** + */ +void rpmdbFreeIterator( /*@only@*/ rpmdbMatchIterator mi); + +/** + */ +unsigned int rpmdbGetIteratorOffset(rpmdbMatchIterator mi); + +/** + */ +Header rpmdbNextIterator(rpmdbMatchIterator mi); + +/** + */ +/*@only@*/ /*@null@*/ rpmdbMatchIterator rpmdbInitIterator(rpmdb db, int dbix, + const void * key, size_t keylen); +#define RPMDBI_PACKAGES 0 +#define RPMDBI_NAME 1 +#define RPMDBI_FILE 2 +#define RPMDBI_GROUP 3 +#define RPMDBI_REQUIREDBY 4 +#define RPMDBI_PROVIDES 5 +#define RPMDBI_CONFLICTS 6 +#define RPMDBI_TRIGGER 7 + /* we pass these around as an array with a sentinel */ typedef struct rpmRelocation_s { const char * oldPath; /* NULL here evals to RPMTAG_DEFAULTPREFIX, */ @@ -799,6 +826,7 @@ typedef int (*QVF_t) (QVA_t *qva, rpmdb db, Header h); /** * @param db rpm database */ +int XshowMatches(QVA_t *qva, /*@only@*/ rpmdbMatchIterator mi, QVF_t showPackage); int showMatches(QVA_t *qva, rpmdb db, dbiIndexSet matches, QVF_t showPackage); #define QUERY_FOR_LIST (1 << 1) |