diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2011-06-08 12:52:12 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2011-06-08 12:52:12 +0300 |
commit | c33ccb71c9226921c4732660e9b408e454c08a4a (patch) | |
tree | a65be6ea95b8b840cf0078aa0acf251669c691cc | |
parent | 5922cc4a0a7e308bbe5e4721bac0383f4b08c8a7 (diff) | |
download | librpm-tizen-c33ccb71c9226921c4732660e9b408e454c08a4a.tar.gz librpm-tizen-c33ccb71c9226921c4732660e9b408e454c08a4a.tar.bz2 librpm-tizen-c33ccb71c9226921c4732660e9b408e454c08a4a.zip |
Add a helper function to convert cursor retrievals to dbiIndexSets
- This stuff is repeated in rpmdb.c all over the place, to some
this suggests making it into a function:
- Hide the DBTs inside the function
- Handle keylen fixups, set conversions and error logging centrally
-rw-r--r-- | lib/rpmdb.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/rpmdb.c b/lib/rpmdb.c index 6f68f3c47..eb983d1de 100644 --- a/lib/rpmdb.c +++ b/lib/rpmdb.c @@ -445,6 +445,39 @@ static dbiIndexSet dbiIndexSetFree(dbiIndexSet set) return NULL; } +static int dbiGetToSet(dbiIndex dbi, const char *keyp, size_t keylen, + dbiIndexSet *set) +{ + int rc = EINVAL; + dbiCursor dbc = dbiCursorInit(dbi, 0); + if (dbc != NULL) { + DBT data, key; + memset(&data, 0, sizeof(data)); + memset(&key, 0, sizeof(key)); + + if (keyp && keylen == 0) { + keylen = strlen(keyp); + if (keylen == 0) + keylen++; /* XXX "/" fixup */ + } + + key.data = (void *) keyp; /* discards const */ + key.size = keylen; + + rc = dbiCursorGet(dbc, &key, &data, DB_SET); + + if (rc == 0) { + dbt2set(dbi, &data, set); + } else if (rc != DB_NOTFOUND) { + rpmlog(RPMLOG_ERR, + _("error(%d) getting \"%s\" records from %s index: %s\n"), + rc, keyp ? keyp : "???", dbiName(dbi), db_strerror(rc)); + } + dbiCursorFree(dbc); + } + return rc; +} + typedef struct miRE_s { rpmTagVal tag; /*!< header tag */ rpmMireMode mode; /*!< pattern match mode */ |