Added config versioning.
authorAndrej Kacian <ticho@claws-mail.org>
Thu, 14 Jul 2016 09:55:54 +0000 (11:55 +0200)
committerAndrej Kacian <ticho@claws-mail.org>
Fri, 15 Jul 2016 15:00:26 +0000 (17:00 +0200)
This allows us to change meaning of existing preferences,
without losing or mangling user data. Controlled by a common
pref "config_version", which is checked on startup after
reading all configuration. If this version is lower than
what is defined in CLAWS_CONFIG_VERSION, an upgrade is done
incrementally, from one version to the next and to the next,
so that all affected preferences are adjusted.

src/Makefile.am
src/main.c
src/prefs_common.c
src/prefs_common.h
src/prefs_migration.c [new file with mode: 0644]
src/prefs_migration.h [new file with mode: 0644]

index 3cb8fd531e0c6e45421fcfedb9bebe1eeaa1b6d9..b840f345a5b78be9c3af5549fcac057f2e52dc60 100644 (file)
@@ -196,6 +196,7 @@ claws_mail_SOURCES = \
        prefs_logging.c \
        prefs_matcher.c \
        prefs_message.c \
+       prefs_migration.c \
        prefs_msg_colors.c \
        prefs_other.c \
        prefs_quote.c \
@@ -314,6 +315,7 @@ claws_mailinclude_HEADERS = \
        prefs_logging.h \
        prefs_matcher.h \
        prefs_message.h \
+       prefs_migration.h \
        prefs_msg_colors.h \
        prefs_other.h \
        prefs_quote.h \
index 19f96f3544b2f0b0e7b2914353dcd928932b2928..388a66f06a368420c4b2b4e520802f60a29b16e3 100644 (file)
@@ -79,6 +79,7 @@
 #include "prefs_fonts.h"
 #include "prefs_image_viewer.h"
 #include "prefs_message.h"
+#include "prefs_migration.h"
 #include "prefs_receive.h"
 #include "prefs_msg_colors.h"
 #include "prefs_quote.h"
@@ -1457,6 +1458,8 @@ int main(int argc, char *argv[])
                g_slist_free(plug_list);
        }
 
+       prefs_update_config_version();
+
        if (never_ran) {
                prefs_common_write_config();
                plugin_load_standard_plugins ();
index f4acf34c01b679c6ac011c3fbef0fcefc1be1c6a..8518f80434b28de849951944931b3ca2bd274fa7 100644 (file)
@@ -141,6 +141,9 @@ static PrefParam param_os_specific[] = {
  */
 
 static PrefParam param[] = {
+       {"config_version", "0",
+        &prefs_common.config_version, P_INT, NULL, NULL, NULL},
+
        /* Receive */
        {"use_ext_inc", "FALSE", &prefs_common.use_extinc, P_BOOL,
         NULL, NULL, NULL},
index e1c2df99398319807eba654d10561f034cedaa1f..ddb455fb9436502bb3f5332a47d7ddf81ca26100 100644 (file)
@@ -36,6 +36,8 @@
 #include "prefs_msg_colors.h"
 #include "prefs_summary_open.h"
 
+#define CLAWS_CONFIG_VERSION 0
+
 typedef struct _PrefsCommon    PrefsCommon;
 
 typedef enum {
@@ -113,6 +115,8 @@ typedef enum
 
 struct _PrefsCommon
 {
+       gint config_version;
+
        /* Receive */
        gboolean use_extinc;
        gchar *extinc_cmd;
diff --git a/src/prefs_migration.c b/src/prefs_migration.c
new file mode 100644 (file)
index 0000000..01e3d44
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2016 the Claws Mail team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#include "claws-features.h"
+#endif
+
+#include "prefs_common.h"
+
+static void _update_config(gint version)
+{
+       switch (version) {
+               case 0:
+               default:
+                       break;
+       }
+}
+
+void prefs_update_config_version()
+{
+       gint ver = prefs_common_get_prefs()->config_version;
+
+       debug_print("Starting config update at config_version %d.\n", ver);
+       if (ver == CLAWS_CONFIG_VERSION) {
+               debug_print("No update necessary, already at latest config_version.\n");
+               return;
+       }
+
+       while (ver < CLAWS_CONFIG_VERSION) {
+               _update_config(ver++);
+               prefs_common_get_prefs()->config_version = ver;
+       }
+
+       debug_print("Config update done.\n");
+}
diff --git a/src/prefs_migration.h b/src/prefs_migration.h
new file mode 100644 (file)
index 0000000..226f1df
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 2016 the Claws Mail team
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef __PREFS_MIGRATION_H__
+#define __PREFS_MIGRATION_H__
+
+void prefs_update_config_version();
+
+#endif /* __PREFS_MIGRATION_H__ */