]> code.citadel.org Git - citadel.git/blobdiff - citadel/database.c
* Applied a patch sent in by Clint Adams <schizo@debian.org> to handle
[citadel.git] / citadel / database.c
index f4050722aee171b2dff9cdf8a59e369159bffc72..934cd69e13c315596d89eb61988ce25004c7a6cd 100644 (file)
@@ -101,6 +101,10 @@ void defrag_databases(void)
        begin_critical_section(S_DIRECTORY);
        gdbm_reorganize(gdbms[CDB_DIRECTORY]);
        end_critical_section(S_DIRECTORY);
+
+       /* defrag the use table */
+       lprintf(7, "Defragmenting the use table\n");
+       gdbm_reorganize(gdbms[CDB_USETABLE]);
 }
 
 
@@ -174,6 +178,14 @@ void open_databases(void)
                        gdbm_strerror(gdbm_errno));
                exit(1);
        }
+       gdbms[CDB_USETABLE] = gdbm_open("data/usetable.gdbm", 0,
+                                       GDBM_WRCREAT, 0600, NULL);
+       if (gdbms[CDB_USETABLE] == NULL) {
+               lprintf(2, "Cannot open use table: %s\n",
+                       gdbm_strerror(gdbm_errno));
+               exit(1);
+       }
+
        /*
           end_critical_section(S_DATABASE);
         */
@@ -387,6 +399,22 @@ struct cdbdata *cdb_next_item(int cdb)
 }
 
 
+/*
+ * Truncate (delete every record)
+ */
+void cdb_trunc(int cdb) {
+       datum key;
+
+       begin_critical_section(S_DATABASE);
+       key = gdbm_firstkey (gdbms[cdb]);
+       while (key = gdbm_firstkey(gdbms[cdb], key.dptr) {
+               gdbm_delete(gdbms[cdb], key);
+       }
+       end_critical_section(S_DATABASE);
+}
+
+
+
 /*
  * empty functions because GDBM doesn't have transaction support
  */