]> 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 c9e4264bc4c5c97386ee24c11a7f724230293fcc..934cd69e13c315596d89eb61988ce25004c7a6cd 100644 (file)
@@ -95,6 +95,16 @@ void defrag_databases(void)
        gdbm_reorganize(gdbms[CDB_FLOORTAB]);
        end_critical_section(S_DATABASE);
        end_critical_section(S_FLOORTAB);
+
+       /* defrag the directory */
+       lprintf(7, "Defragmenting the directory\n");
+       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]);
 }
 
 
@@ -161,6 +171,21 @@ void open_databases(void)
                        gdbm_strerror(gdbm_errno));
                exit(1);
        }
+       gdbms[CDB_DIRECTORY] = gdbm_open("data/directory.gdbm", 0,
+                                       GDBM_WRCREAT, 0600, NULL);
+       if (gdbms[CDB_DIRECTORY] == NULL) {
+               lprintf(2, "Cannot open directory: %s\n",
+                       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);
         */
@@ -374,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
  */