DBT key, data;
int ret;
+ LOG(log_maxdebug, logtype_cnid, "dbif_getversion: reading version info");
+
+ *version = -1;
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
key.data = ROOTINFO_KEY;
ret = 1;
break;
case 0: /* not found */
+ LOG(log_debug, logtype_cnid, "dbif_getversion: no version info found");
ret = 0;
break;
default:
+ LOG(log_error, logtype_cnid, "dbif_getversion: database error");
ret = -1;
break;
}
}
/*!
- * Upgrade CNID database versions
+ * Upgrade CNID database versions, initialize rootinfo key as as necessary in dbif_setversion()
*
* For now this does nothing, as upgrading from ver. 0 to 1 is done in dbif_open
*/
+#define UNINTIALIZED_DB UINT32_MAX
static int dbif_upgrade(DBD *dbd)
{
- uint32_t version;
+ uint32_t version = CNID_VERSION_UNINTIALIZED_DB;
if (dbif_getversion(dbd, &version) == -1)
return -1;
+ if (version == CNID_VERSION_UNINTIALIZED_DB) {
+ version = CNID_VERSION;
+ if (dbif_setversion(dbd, CNID_VERSION) != 0)
+ return -1;
+ }
/*
* Do upgrade stuff ...
if (reindex)
LOG(log_info, logtype_cnid, "Reindexing name index...");
+ /*
+ * Upgrading from version 0 to 1 requires adding the name index below which
+ * must be done by specifying the DB_CREATE flag
+ */
uint32_t version = CNID_VERSION;
if (dbd->db_envhome && !reindex) {
if (dbif_getversion(dbd, &version) == -1)
* 0: up to Netatalk 2.1.x
* 1: starting with 2.2, additional name index, used in cnid_find
*/
-#define CNID_VERSION_0 0
-#define CNID_VERSION_1 1
+#define CNID_VERSION_0 0
+#define CNID_VERSION_1 1
+#define CNID_VERSION_UNINTIALIZED_DB UINT32_MAX
/* Current CNID version */
#define CNID_VERSION CNID_VERSION_1