diff options
author | Florian Festi <ffesti@redhat.com> | 2010-10-24 19:10:35 +0200 |
---|---|---|
committer | Florian Festi <ffesti@redhat.com> | 2010-11-03 10:03:14 +0100 |
commit | 2946c185fa03c4847b32d230b10b641b4baa7466 (patch) | |
tree | 4a7db428c98548c746cb4aa41e699de0f65368bb /lib | |
parent | 968461689c6eecb85e5634ef72f503cef34572d3 (diff) | |
download | librpm-tizen-2946c185fa03c4847b32d230b10b641b4baa7466.tar.gz librpm-tizen-2946c185fa03c4847b32d230b10b641b4baa7466.tar.bz2 librpm-tizen-2946c185fa03c4847b32d230b10b641b4baa7466.zip |
Give access to the pkg offset and tag num of the index entry the key iterator is pointing to
Diffstat (limited to 'lib')
-rw-r--r-- | lib/rpmdb.c | 31 | ||||
-rw-r--r-- | lib/rpmdb.h | 23 |
2 files changed, 52 insertions, 2 deletions
diff --git a/lib/rpmdb.c b/lib/rpmdb.c index ce7c70578..32f2c54ec 100644 --- a/lib/rpmdb.c +++ b/lib/rpmdb.c @@ -517,6 +517,7 @@ struct rpmdbKeyIterator_s { rpmDbiTagVal ki_rpmtag; DBC * ki_dbc; DBT ki_key; + dbiIndexSet ki_set; }; static rpmdb rpmdbRock; @@ -2266,6 +2267,7 @@ rpmdbKeyIterator rpmdbKeyIteratorInit(rpmdb db, rpmDbiTagVal rpmtag) ki->ki_db = rpmdbLink(db); ki->ki_rpmtag = rpmtag; ki->ki_dbi = dbi; + ki->ki_set = NULL; return ki; } @@ -2282,7 +2284,6 @@ int rpmdbKeyIteratorNext(rpmdbKeyIterator ki) xx = dbiCopen(ki->ki_dbi, &ki->ki_dbc, 0); memset(&data, 0, sizeof(data)); - data.flags = DB_DBT_PARTIAL; rc = dbiGet(ki->ki_dbi, ki->ki_dbc, &ki->ki_key, &data, DB_NEXT); if (rc != 0 && rc != DB_NOTFOUND) { @@ -2290,6 +2291,9 @@ int rpmdbKeyIteratorNext(rpmdbKeyIterator ki) _("error(%d:%s) getting next key from %s index\n"), rc, db_strerror(rc), rpmTagGetName(ki->ki_rpmtag)); } + ki->ki_set = dbiFreeIndexSet(ki->ki_set); + (void) dbt2set(ki->ki_dbi, &data, &ki->ki_set); + return rc; } @@ -2305,6 +2309,28 @@ size_t rpmdbKeyIteratorKeySize(rpmdbKeyIterator ki) return (size_t)(ki->ki_key.size); } +int rpmdbKeyIteratorNumPkgs(rpmdbKeyIterator ki) +{ + return (ki && ki->ki_set) ? dbiIndexSetCount(ki->ki_set) : 0; +} + +int rpmdbKeyIteratorPkgOffset(rpmdbKeyIterator ki, int nr) +{ + if (!ki || !ki->ki_set) + return -1; + if (dbiIndexSetCount(ki->ki_set) <= nr) + return -1; + return dbiIndexRecordOffset(ki->ki_set, nr); +} + +int rpmdbKeyIteratorTagNum(rpmdbKeyIterator ki, int nr) +{ + if (!ki || !ki->ki_set) + return -1; + if (dbiIndexSetCount(ki->ki_set) <= nr) + return -1; + return dbiIndexRecordFileNumber(ki->ki_set, nr); +} rpmdbKeyIterator rpmdbKeyIteratorFree(rpmdbKeyIterator ki) { @@ -2325,8 +2351,9 @@ rpmdbKeyIterator rpmdbKeyIteratorFree(rpmdbKeyIterator ki) if (ki->ki_dbc) xx = dbiCclose(ki->ki_dbi, ki->ki_dbc, 0); ki->ki_dbc = NULL; - ki->ki_dbi = NULL; /* ??? */ + ki->ki_dbi = NULL; ki->ki_db = rpmdbUnlink(ki->ki_db); + ki->ki_set = dbiFreeIndexSet(ki->ki_set); ki = _free(ki); return ki; diff --git a/lib/rpmdb.h b/lib/rpmdb.h index 0473a836b..80e25c6e5 100644 --- a/lib/rpmdb.h +++ b/lib/rpmdb.h @@ -249,6 +249,29 @@ const void * rpmdbKeyIteratorKey(rpmdbKeyIterator ki); size_t rpmdbKeyIteratorKeySize(rpmdbKeyIterator ki); /** \ingroup rpmdb + * Get number of entries for current key + * @param ki key iterator + * @return number of entries. -1 on error. + */ +int rpmdbKeyIteratorNumPkgs(rpmdbKeyIterator ki); + +/** \ingroup rpmdb + * Get package offset of entry + * @param ki key iterator + * @param nr number of the entry + * @return db offset of pkg + */ +int rpmdbKeyIteratorPkgOffset(rpmdbKeyIterator ki, int nr); + +/** \ingroup rpmdb + * Get tag number of entry + * @param ki key iterator + * @param nr number of the entry + * @return number of tag within the package + */ +int rpmdbKeyIteratorTagNum(rpmdbKeyIterator ki, int nr); + +/** \ingroup rpmdb * Free key iterator * @param ki key iterator * return NULL |