[evolution-data-server] BUGFIX: #578910 - Fixes problem of missing migration for left out



commit 6fc452c253432cb8c4fb617968c7949c3c3a4833
Author: Srinivasa Ragavan <sragavan novell com>
Date:   Thu Aug 27 10:34:17 2009 +0530

    BUGFIX: #578910 - Fixes problem of missing migration for left out
    folders.

 camel/camel-db.c             |   25 +++++++++++++++++++++++++
 camel/camel-db.h             |    3 +++
 camel/camel-folder-summary.c |   21 +++++++++++++++++++++
 3 files changed, 49 insertions(+), 0 deletions(-)
---
diff --git a/camel/camel-db.c b/camel/camel-db.c
index b994e99..0c19e7c 100644
--- a/camel/camel-db.c
+++ b/camel/camel-db.c
@@ -1250,6 +1250,31 @@ camel_db_migrate_folder_recreate (CamelDB *cdb, const gchar *folder_name, gint v
 	return ret;
 }
 
+gint
+camel_db_reset_folder_version (CamelDB *cdb, const gchar *folder_name, gint reset_version, CamelException *ex)
+{
+	gint ret = 0;
+	gchar *version_creation_query;
+	gchar *version_insert_query;
+	gchar *drop_folder_query;
+
+
+	drop_folder_query = sqlite3_mprintf ("DROP TABLE IF EXISTS '%q_version'", folder_name);
+	version_creation_query = sqlite3_mprintf ("CREATE TABLE IF NOT EXISTS '%q_version' ( version TEXT )", folder_name);
+
+	version_insert_query = sqlite3_mprintf ("INSERT INTO '%q_version' VALUES ('%d')", folder_name, reset_version);
+
+	ret = camel_db_add_to_transaction (cdb, drop_folder_query, ex);
+	ret = camel_db_add_to_transaction (cdb, version_creation_query, ex);
+	ret = camel_db_add_to_transaction (cdb, version_insert_query, ex);
+
+	sqlite3_free (drop_folder_query);
+	sqlite3_free (version_creation_query);
+	sqlite3_free (version_insert_query);
+
+	return ret;
+}
+
 static gint
 camel_db_write_folder_version (CamelDB *cdb, const gchar *folder_name, gint old_version, CamelException *ex)
 {
diff --git a/camel/camel-db.h b/camel/camel-db.h
index 2df1616..540f5da 100644
--- a/camel/camel-db.h
+++ b/camel/camel-db.h
@@ -177,5 +177,8 @@ gint camel_db_flush_in_memory_transactions (CamelDB *cdb, const gchar * folder_n
 GHashTable *
 camel_db_get_folder_preview (CamelDB *db, gchar *folder_name, CamelException *ex);
 gint camel_db_write_preview_record (CamelDB *db, gchar *folder_name, const gchar *uid, const gchar *msg, CamelException *ex);
+
+gint
+camel_db_reset_folder_version (CamelDB *cdb, const gchar *folder_name, gint reset_version, CamelException *ex);
 #endif
 
diff --git a/camel/camel-folder-summary.c b/camel/camel-folder-summary.c
index baf398b..28d2c2f 100644
--- a/camel/camel-folder-summary.c
+++ b/camel/camel-folder-summary.c
@@ -952,9 +952,11 @@ preview_update_exec (CamelSession *session, CamelSessionThreadMsg *msg)
 		camel_pstring_free (uids_uncached->pdata[i]); /* unref the hash table key */
 	}
 
+	CAMEL_FOLDER_REC_LOCK(m->folder, lock);
 	camel_db_begin_transaction (m->folder->parent_store->cdb_w, NULL);
 	g_hash_table_foreach (hash, (GHFunc)msg_update_preview, m->folder);
 	camel_db_end_transaction (m->folder->parent_store->cdb_w, NULL);
+	CAMEL_FOLDER_REC_UNLOCK(m->folder, lock);
 	camel_folder_free_uids(m->folder, uids_uncached);
 	camel_folder_summary_free_hashtable (hash);
 }
@@ -1578,6 +1580,25 @@ camel_folder_summary_save_to_db (CamelFolderSummary *s, CamelException *ex)
 		s->flags |= CAMEL_SUMMARY_DIRTY;
 		return -1;
 	}
+	
+	printf("WARNING %s\n", camel_exception_get_description (ex));
+	if (strstr (camel_exception_get_description (ex), "26 columns but 28 values") != NULL) {
+		/* This is an error is previous migration. Let remigrate this folder alone. */
+		camel_db_abort_transaction (cdb, ex);
+		camel_db_reset_folder_version (cdb, s->folder->full_name, 0, ex);
+		g_warning ("Fixing up a broken summary migration\n");
+		/* Begin everything again. */
+		camel_db_begin_transaction (cdb, ex);
+
+		ret = save_message_infos_to_db (s, FALSE, ex);
+		if (ret != 0) {
+			camel_db_abort_transaction (cdb, ex);
+			/* Failed, so lets reset the flag */
+			s->flags |= CAMEL_SUMMARY_DIRTY;
+			return -1;
+		}
+	}
+
 
 	camel_db_end_transaction (cdb, ex);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]