#define ENTRIES_BLOCK 255
#define NAMEDATA_BLOCK 1023
-#define FLAGS_GET_PUBKEYS 1
-
static struct rpmdbentry *
-getinstalledrpmdbids(struct rpm_by_state *state, const char *index, const char *match, int *nentriesp, char **namedatap, int flags)
+getinstalledrpmdbids(struct rpm_by_state *state, const char *index, const char *match, int *nentriesp, char **namedatap)
{
DB_ENV *dbenv = 0;
DB *db = 0;
}
while (dbc->c_get(dbc, &dbkey, &dbdata, match ? DB_SET : DB_NEXT) == 0)
{
- if (!match)
- {
- if ((flags & FLAGS_GET_PUBKEYS))
- {
- if (dbkey.size != 10 || memcmp(dbkey.data, "gpg-pubkey", 10))
- continue;
- }
- else
- {
- if (dbkey.size == 10 && !memcmp(dbkey.data, "gpg-pubkey", 10))
- continue;
- }
- }
+ if (!match && dbkey.size == 10 && !memcmp(dbkey.data, "gpg-pubkey", 10))
+ continue;
dl = dbdata.size;
dp = dbdata.data;
while(dl >= 8)
return entries;
}
+static void
+freestate(struct rpm_by_state *state)
+{
+ /* close down */
+ if (!state)
+ return;
+ if (state->db)
+ state->db->close(state->db, 0);
+ if (state->dbenv)
+ state->dbenv->close(state->dbenv, 0);
+ sat_free(state->rpmhead);
+}
+
int
rpm_installedrpmdbids(const char *rootdir, const char *index, const char *match, Queue *rpmdbidq)
{
memset(&state, 0, sizeof(state));
if (!(state.dbenv = opendbenv(rootdir)))
return 0;
- entries = getinstalledrpmdbids(&state, index, match, &nentries, &namedata, 0);
+ entries = getinstalledrpmdbids(&state, index, match, &nentries, &namedata);
if (rpmdbidq)
for (i = 0; i < nentries; i++)
queue_push(rpmdbidq, entries[i].rpmdbid);
sat_free(entries);
sat_free(namedata);
- rpm_byrpmdbid(0, 0, (void **)&state);
+ freestate(&state);
return nentries;
}
if (!rpmdbid)
{
/* close down */
- if (!state)
- return 0;
- if (state->db)
- state->db->close(state->db, 0);
- if (state->dbenv)
- state->dbenv->close(state->dbenv, 0);
- sat_free(state->rpmhead);
+ freestate(state);
sat_free(state);
*statep = (void *)0;
return 0;
memset(&state, 0, sizeof(state));
if (!(state.dbenv = opendbenv(rootdir)))
return;
- entries = getinstalledrpmdbids(&state, "Name", 0, &nentries, &namedata, FLAGS_GET_PUBKEYS);
+ entries = getinstalledrpmdbids(&state, "Name", "gpg-pubkey", &nentries, &namedata);
for (i = 0 ; i < nentries; i++)
{
- RpmHead *rpmhead = rpm_byrpmdbid(entries[i].rpmdbid, rootdir, (void **)&state);
+ void *statep = &state;
+ RpmHead *rpmhead = rpm_byrpmdbid(entries[i].rpmdbid, rootdir, &statep);
if (!rpmhead)
continue;
str = headstring(rpmhead, TAG_DESCRIPTION);
repo->rpmdbid = repo_sidedata_create(repo, sizeof(Id));
repo->rpmdbid[s - pool->solvables - repo->start] = entries[i].rpmdbid;
}
- rpm_byrpmdbid(0, 0, (void **)&state);
+ freestate(&state);
if (!(flags & REPO_NO_INTERNALIZE))
repodata_internalize(data);
}