talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit 5bcc8ead3ddf78902cb940ba7659acf335f78247
parent 9145ce96aff60a221244ca5245a594f72aaa8e89
Author: Andrej Kacian <ticho@claws-mail.org>
Date:   Fri, 19 Jan 2018 18:56:52 +0100

Implement config_version in folderlist.xml.

Diffstat:
Msrc/folder.c | 23++++++++++++++++++++++-
Msrc/prefs_migration.c | 46++++++++++++++++++++++++++++++++++++++++++++++
Msrc/prefs_migration.h | 1+
3 files changed, 69 insertions(+), 1 deletion(-)

diff --git a/src/folder.c b/src/folder.c @@ -61,9 +61,10 @@ #include "main.h" #include "msgcache.h" #include "privacy.h" +#include "prefs_common.h" +#include "prefs_migration.h" /* Dependecies to be removed ?! */ -#include "prefs_common.h" #include "prefs_account.h" /* Define possible missing constants for Windows. */ @@ -830,6 +831,8 @@ gint folder_read_list(void) GNode *node, *cur; XMLNode *xmlnode; gchar *path; + GList *list; + gint config_version = -1; path = folder_get_list_path(); if (!is_file_exist(path)) return -1; @@ -856,7 +859,23 @@ gint folder_read_list(void) cur = cur->next; } + for (list = xmlnode->tag->attr; list != NULL; list = list->next) { + XMLAttr *attr = list->data; + + if (!attr || !attr->name || !attr->value) continue; + if (!strcmp(attr->name, "config_version")) { + config_version = atoi(attr->value); + debug_print("Found folderlist config_version %d\n", config_version); + } + } + xml_free_tree(node); + + if (prefs_update_config_version_folderlist(config_version) < 0) { + debug_print("Folderlist configuration file version upgrade failed\n"); + return -2; + } + if (folder_list || folder_unloaded_list) return 0; else @@ -883,6 +902,8 @@ void folder_write_list(void) return; } tag = xml_tag_new("folderlist"); + xml_tag_add_attr(tag, xml_attr_new_int("config_version", + CLAWS_CONFIG_VERSION)); xmlnode = xml_node_new(tag, NULL); diff --git a/src/prefs_migration.c b/src/prefs_migration.c @@ -147,6 +147,22 @@ static void _update_config_password_store(gint version) } } +static void _update_config_folderlist(gint version) +{ + debug_print("Folderlist: Updating config version from %d to %d.\n", + version, version + 1); + + switch (version) { + /* nothing here yet */ + + default: + + /* NOOP */ + + break; + } +} + int prefs_update_config_version_common() { gint ver = prefs_common_get_prefs()->config_version; @@ -241,3 +257,33 @@ int prefs_update_config_version_password_store() debug_print("Config update done.\n"); return 1; } + +int prefs_update_config_version_folderlist(gint from_version) +{ + gint ver = from_version; + + if (ver == -1) { + /* There was no config_version stored in the config, let's assume + * config_version same as clawsrc started at, to avoid breaking + * the configuration by "upgrading" it unnecessarily. */ + debug_print("Folderlist: config_version not saved, using one from clawsrc: %d\n", starting_config_version); + ver = starting_config_version; + } + + debug_print("Starting config_update at config_version %d,\n", ver); + + if (!_version_check(ver)) + return -1; + + if (ver == CLAWS_CONFIG_VERSION) { + debug_print("No update necessary, already at latest config_version.\n"); + return 0; /* nothing to do */ + } + + while (ver < CLAWS_CONFIG_VERSION) { + _update_config_folderlist(ver++); + } + + debug_print("Config update done.\n"); + return 1; +} diff --git a/src/prefs_migration.h b/src/prefs_migration.h @@ -22,5 +22,6 @@ int prefs_update_config_version_common(); int prefs_update_config_version_accounts(); int prefs_update_config_version_password_store(); +int prefs_update_config_version_folderlist(gint from_version); #endif /* __PREFS_MIGRATION_H__ */