Test for existing BDB files (not used yet)
authorArt Cancro <ajc@citadel.org>
Tue, 16 Apr 2024 15:20:56 +0000 (08:20 -0700)
committerArt Cancro <ajc@citadel.org>
Tue, 16 Apr 2024 15:20:56 +0000 (08:20 -0700)
citadel/server/backends/common/database.c

index 67022f7436335f98af9ba1d9400ecd3c86247fa5..a07dd22e652d9dc46d1aa8214abe8152d20d12e8 100644 (file)
@@ -1,6 +1,5 @@
-// Copyright (c) 1987-2023 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.
+// Copyright (c) 1987-2024 by the citadel.org team
+// This program is open source software.  Use, duplication, or disclosure is subject to the GNU General Public License version 3.
 
 // The functions in this file handle the selection and activation of a storage backend for Citadel Server.
 // Right now, it simply activates Berkeley DB because that's the only one we have.
@@ -43,7 +42,22 @@ void                 (*cdb_tick)(void)                                       = NULL;
 
 // This function is responsible for choosing and initializing a back end.
 void cdb_init_backends(void) {
-       cdb_chmod_data();
+
+       cdb_chmod_data();               // Set file level permissions so we can actually access the data files
+
+       // 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) {
+               char junk[12];
+               uint32_t magic;
+               read(fd, junk, 12);     // throw the first 12 bytes away
+               read(fd, &magic, sizeof(magic));
+               if (magic == 0x00053162) {
+                       syslog(LOG_DEBUG, "db: found existing Citadel database in Berkeley DB format");
+               }
+               close(fd);
+       }
+
        bdb_init_backend();             // for now, this is the only one, so we select it always.
 }