more noodling on backend detection
authorArt Cancro <ajc@citadel.org>
Tue, 16 Apr 2024 19:20:35 +0000 (12:20 -0700)
committerArt Cancro <ajc@citadel.org>
Tue, 16 Apr 2024 19:20:35 +0000 (12:20 -0700)
citadel/server/backends/berkeley_db/berkeley_db.h
citadel/server/backends/common/database.c

index 651376a01355ea045b74083788a8806c209b1d32..188b1ecae7c1a41dae1a6343c696ea18810bcd7b 100644 (file)
@@ -1,6 +1,7 @@
-// Copyright (c) 1987-2023 by the citadel.org team
+// Copyright (c) 1987-2024 by the citadel.org team
 //
-// This program is open source software.  Use, duplication, or disclosure
-// is subject to the terms of the GNU General Public License, version 3.
+// This program is open source software.  Use, duplication, or disclosure is subject to the GNU General Public License version 3.
+
+#define THIS_BUILD_CONTAINS_BDB
 
 void bdb_init_backend(void);
index a07dd22e652d9dc46d1aa8214abe8152d20d12e8..0b8276b0713ee9fca754bc97e3c91e36eca35929 100644 (file)
@@ -43,8 +43,11 @@ void                 (*cdb_tick)(void)                                       = NULL;
 // This function is responsible for choosing and initializing a back end.
 void cdb_init_backends(void) {
 
+       char *chosen_backend = NULL;
+
        cdb_chmod_data();               // Set file level permissions so we can actually access the data files
 
+#ifdef THIS_BUILD_CONTAINS_BDB
        // Test for Berkeley DB (this does nothing yet -- we're preparing to test for multiple back ends in the future)
        int fd = open(ctdl_db_dir"/cdb.00", O_RDONLY);
        if (fd) {
@@ -54,11 +57,23 @@ void cdb_init_backends(void) {
                read(fd, &magic, sizeof(magic));
                if (magic == 0x00053162) {
                        syslog(LOG_DEBUG, "db: found existing Citadel database in Berkeley DB format");
+                       if (!chosen_backend) {
+                               chosen_backend = "bdb";
+                       }
                }
                close(fd);
        }
+#endif
 
-       bdb_init_backend();             // for now, this is the only one, so we select it always.
+       // If no existing database has been detected, go with Berkeley DB.
+       if (!chosen_backend) {
+               chosen_backend = "bdb";
+       }
+
+       // Initialize the chosen backend.
+       if (!strcmp(chosen_backend, "bdb")) {
+               bdb_init_backend();
+       }
 }