[Commits] [SCM] claws branch, master, updated. 3.16.0-18-ga96fdf2

ticho at claws-mail.org ticho at claws-mail.org
Fri Jan 19 19:16:48 CET 2018


The branch, master has been updated
       via  a96fdf2c4ea562761d2b92c33f904b5dbb70acea (commit)
      from  a9608e4cd547e403b87feccd13817e14f4a10d97 (commit)

Summary of changes:
 src/main.c            |    7 +++----
 src/passwordstore.c   |   29 +++++++++++++++++++----------
 src/passwordstore.h   |    2 +-
 src/prefs_migration.c |   13 ++++---------
 src/prefs_migration.h |    2 +-
 5 files changed, 28 insertions(+), 25 deletions(-)


- Log -----------------------------------------------------------------
commit a96fdf2c4ea562761d2b92c33f904b5dbb70acea
Author: Andrej Kacian <ticho at claws-mail.org>
Date:   Fri Jan 19 19:16:44 2018 +0100

    Handle password store config_version update without the global gint variable.

diff --git a/src/main.c b/src/main.c
index 1610953..1d2654c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1331,10 +1331,8 @@ int main(int argc, char *argv[])
 	folderview_freeze(mainwin->folderview);
 	folder_item_update_freeze();
 
-	passwd_store_read_config();
-
-	if (prefs_update_config_version_password_store() < 0) {
-		debug_print("Password store configuration file version upgrade failed, exiting\n");
+	if ((ret = passwd_store_read_config()) < 0) {
+		debug_print("Password store configuration file version upgrade failed (%d), exiting\n", ret);
 #ifdef G_OS_WIN32
 		win32_close_log();
 #endif
@@ -1363,6 +1361,7 @@ int main(int argc, char *argv[])
 	 * or a failed config_version upgrade.
 	 */
 	if ((ret = folder_read_list()) < 0) {
+		debug_print("Folderlist read failed (%d)\n", ret);
 		prefs_destroy_cache();
 		
 		if (ret == -2) {
diff --git a/src/passwordstore.c b/src/passwordstore.c
index 84119c5..2f1d6c1 100644
--- a/src/passwordstore.c
+++ b/src/passwordstore.c
@@ -34,10 +34,11 @@
 #include "common/utils.h"
 #include "passwordstore.h"
 #include "password.h"
+#include "prefs_common.h"
 #include "prefs_gtk.h"
+#include "prefs_migration.h"
 
 static GSList *_password_store;
-gint _password_store_config_version = -1;
 
 /* Finds password block of given type and name in the pwdstore. */
 static PasswordBlock *_get_block(PasswordBlockType block_type,
@@ -310,7 +311,7 @@ static gint _write_to_file(FILE *fp)
 	gchar *typestr, *line, *key, *pwd;
 
 	/* Write out the config_version */
-	line = g_strdup_printf("[config_version:%d]\n", _password_store_config_version);
+	line = g_strdup_printf("[config_version:%d]\n", CLAWS_CONFIG_VERSION);
 	if (fputs(line, fp) == EOF) {
 		FILE_OP_ERROR("password store, config_version", "fputs");
 		g_free(line);
@@ -406,7 +407,7 @@ void passwd_store_write_config(void)
 	}
 }
 
-void passwd_store_read_config(void)
+int passwd_store_read_config(void)
 {
 	gchar *rcpath, *contents, **lines, **line, *typestr, *name;
 	GError *error = NULL;
@@ -414,7 +415,7 @@ void passwd_store_read_config(void)
 	PasswordBlock *block = NULL;
 	PasswordBlockType type;
 	gboolean reading_config_version = FALSE;
-	gint ver = -1;
+	gint config_version = -1;
 
 	/* TODO: passwd_store_clear(); */
 
@@ -427,7 +428,7 @@ void passwd_store_read_config(void)
 		g_warning("couldn't read password store from file: %s", error->message);
 		g_error_free(error);
 		g_free(rcpath);
-		return;
+		return -1;
 	}
 	g_free(rcpath);
 
@@ -453,7 +454,7 @@ void passwd_store_read_config(void)
 					type = PWS_PLUGIN;
 				} else if (!strcmp(typestr, "config_version")) {
 					reading_config_version = TRUE;
-					ver = atoi(name);
+					config_version = atoi(name);
 				} else {
 					debug_print("Unknown password block type: '%s'\n", typestr);
 					g_strfreev(line);
@@ -461,12 +462,13 @@ void passwd_store_read_config(void)
 				}
 
 				if (reading_config_version) {
-					if (ver < 0) {
-						debug_print("config_version:%d looks invalid, ignoring it\n", ver);
+					if (config_version < 0) {
+						debug_print("config_version:%d looks invalid, ignoring it\n",
+								config_version);
+						config_version = -1; /* set to default value if missing */
 						i++; continue;
 					}
-					debug_print("config_version in file is %d\n", ver);
-					_password_store_config_version = ver;
+					debug_print("config_version in file is %d\n", config_version);
 					reading_config_version = FALSE;
 				} else {
 					if ((block = _new_block(type, name)) == NULL) {
@@ -494,4 +496,11 @@ void passwd_store_read_config(void)
 		i++;
 	}
 	g_strfreev(lines);
+
+	if (prefs_update_config_version_password_store(config_version) < 0) {
+		debug_print("Password store configuration file version upgrade failed\n");
+		return -2;
+	}
+
+	return g_slist_length(_password_store);
 }
diff --git a/src/passwordstore.h b/src/passwordstore.h
index 20d2c6b..d9d3fed 100644
--- a/src/passwordstore.h
+++ b/src/passwordstore.h
@@ -67,7 +67,7 @@ void passwd_store_reencrypt_all(const gchar *old_mpwd,
 
 /* Writes/reads password store to/from file. */
 void passwd_store_write_config(void);
-void passwd_store_read_config(void);
+int passwd_store_read_config(void);
 
 /* Convenience wrappers for handling account passwords.
  * (This is to save some boilerplate code converting account_id to
diff --git a/src/prefs_migration.c b/src/prefs_migration.c
index 04f20a6..7bd57a2 100644
--- a/src/prefs_migration.c
+++ b/src/prefs_migration.c
@@ -34,8 +34,6 @@
 #include "prefs_common.h"
 #include "alertpanel.h"
 
-extern gint _password_store_config_version;
-
 static gint starting_config_version = 0;
 
 gboolean _version_check(gint ver)
@@ -225,20 +223,18 @@ int prefs_update_config_version_accounts()
 	return 1;
 }
 
-int prefs_update_config_version_password_store()
+int prefs_update_config_version_password_store(gint from_version)
 {
-	gint ver;
+	gint ver = from_version;
 
-	if (_password_store_config_version == -1) {
+	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("Password store: config_version not saved, using one from clawsrc: %d\n", starting_config_version);
-		_password_store_config_version = starting_config_version;
+		ver = starting_config_version;
 	}
 
-	ver = _password_store_config_version;
-
 	debug_print("Starting config update at config_version %d.\n", ver);
 
 	if (!_version_check(ver))
@@ -251,7 +247,6 @@ int prefs_update_config_version_password_store()
 
 	while (ver < CLAWS_CONFIG_VERSION) {
 		_update_config_password_store(ver++);
-		_password_store_config_version = ver;
 	}
 
 	debug_print("Config update done.\n");
diff --git a/src/prefs_migration.h b/src/prefs_migration.h
index 05e2da6..047c7c0 100644
--- a/src/prefs_migration.h
+++ b/src/prefs_migration.h
@@ -21,7 +21,7 @@
 
 int prefs_update_config_version_common();
 int prefs_update_config_version_accounts();
-int prefs_update_config_version_password_store();
+int prefs_update_config_version_password_store(gint from_version);
 int prefs_update_config_version_folderlist(gint from_version);
 
 #endif /* __PREFS_MIGRATION_H__ */

-----------------------------------------------------------------------


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list