9 dbiIndex * dbiOpenIndex(char * filename, int flags, int perms) {
12 db = malloc(sizeof(*db));
13 db->indexname = strdup(filename);
14 db->db = dbopen(filename, flags, perms, DB_HASH, NULL);
18 rpmError(RPMERR_DBOPEN, "cannot open file %s: ", filename,
26 void dbiCloseIndex(dbiIndex * dbi) {
27 dbi->db->close(dbi->db);
32 void dbiSyncIndex(dbiIndex * dbi) {
33 dbi->db->sync(dbi->db, 0);
36 int dbiSearchIndex(dbiIndex * dbi, char * str, dbiIndexSet * set) {
41 key.size = strlen(str);
43 rc = dbi->db->get(dbi->db, &key, &data, 0);
45 rpmError(RPMERR_DBGETINDEX, "error getting record %s from %s",
52 set->recs = data.data;
53 set->recs = malloc(data.size);
54 memcpy(set->recs, data.data, data.size);
55 set->count = data.size / sizeof(dbiIndexRecord);
59 int dbiUpdateIndex(dbiIndex * dbi, char * str, dbiIndexSet * set) {
65 key.size = strlen(str);
68 data.data = set->recs;
69 data.size = set->count * sizeof(dbiIndexRecord);
71 rc = dbi->db->put(dbi->db, &key, &data, 0);
73 rpmError(RPMERR_DBPUTINDEX, "error storing record %s into %s",
78 rc = dbi->db->del(dbi->db, &key, 0);
80 rpmError(RPMERR_DBPUTINDEX, "error removing record %s into %s",
89 int dbiAppendIndexRecord(dbiIndexSet * set, dbiIndexRecord rec) {
92 if (set->count == 1) {
93 set->recs = malloc(set->count * sizeof(dbiIndexRecord));
95 set->recs = realloc(set->recs, set->count * sizeof(dbiIndexRecord));
97 set->recs[set->count - 1] = rec;
102 dbiIndexSet dbiCreateIndexRecord(void) {
109 void dbiFreeIndexRecord(dbiIndexSet set) {
113 /* returns 1 on failure */
114 int dbiRemoveIndexRecord(dbiIndexSet * set, dbiIndexRecord rec) {
117 int num = set->count;
120 for (from = 0; from < num; from++) {
121 if (rec.recOffset != set->recs[from].recOffset ||
122 rec.fileNumber != set->recs[from].fileNumber) {
123 if (from != to) set->recs[to] = set->recs[from];
131 return (numCopied == num);