patch for bug 312857



Hi,
The summary for the groupwise provider is messed up since 2 threads are
modifying at the same time. The patch makes sure that we try and lock
before we modify the summary.
Also we make sure that the item exists in the summary before actually
trying to delete it.

Thanks,
vivek
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/providers/groupwise/ChangeLog,v
retrieving revision 1.109
diff -u -p -r1.109 ChangeLog
--- ChangeLog	2 Sep 2005 08:55:43 -0000	1.109
+++ ChangeLog	2 Sep 2005 12:46:51 -0000
@@ -1,5 +1,16 @@
 2005-09-02 Vivek Jain <jvivek novell com>
 	
+	* camel-groupwise-folder.c:(groupwise_sync)
+	whenever we perform any junk operation we have to
+	start all over again
+	(transfer_messages_to): remove the item info from summary and 
+	cache if it was a move operation.
+	(gw_update_all_items): check before you try to remove from the 
+	summary and cache
+	**Fixes #312857
+
+2005-09-02 Vivek Jain <jvivek novell com>
+	
 	* camel-groupwise-folder.c: (groupwise_folder_item_to_msg)
 	check contentType to be NULL before we set it.
 	**Fixes #310953
Index: camel-groupwise-folder.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/providers/groupwise/camel-groupwise-folder.c,v
retrieving revision 1.93
diff -u -p -r1.93 camel-groupwise-folder.c
--- camel-groupwise-folder.c	2 Sep 2005 08:55:43 -0000	1.93
+++ camel-groupwise-folder.c	2 Sep 2005 12:46:51 -0000
@@ -91,6 +91,8 @@ static CamelMimeMessage *groupwise_folde
 
 #define d(x) x
 
+static GMutex *mutex = NULL;
+
 static CamelMimeMessage *
 groupwise_folder_get_message( CamelFolder *folder,
 		const char *uid,
@@ -564,24 +566,38 @@ groupwise_sync (CamelFolder *folder, gbo
 	if (((CamelOfflineStore *) gw_store)->state == CAMEL_OFFLINE_STORE_NETWORK_UNAVAIL) 
 		return;
 	
-	container_id =  camel_groupwise_store_container_id_lookup (gw_store, folder->full_name) ;
+	if (!mutex)
+		mutex = g_mutex_new ();
 
+	if (!g_mutex_try_lock (mutex))
+		return;
+
+	container_id =  camel_groupwise_store_container_id_lookup (gw_store, folder->full_name) ;
 
 	count = camel_folder_summary_count (folder->summary);
 	for (i=0 ; i <count ; i++) {
 		guint32 flags = 0;
 		info = camel_folder_summary_index (folder->summary, i);
 		gw_info = (CamelGroupwiseMessageInfo *) info;
-		
+
 		/**Junk Mail handling**/
 		if(!info)
 			continue;
 		flags = camel_message_info_flags (info);	
 
-		if ((flags & CAMEL_MESSAGE_JUNK) && !(flags & CAMEL_GW_MESSAGE_JUNK)) /*marked a message junk*/
-			move_to_junk (folder, info, ex);
-		else if ((flags & CAMEL_MESSAGE_JUNK) && (flags & CAMEL_GW_MESSAGE_JUNK)) /*message was marked as junk, now unjunk*/ 
-			move_to_mailbox (folder, info, ex);
+		if ((flags & CAMEL_MESSAGE_JUNK)) {
+			if (!(flags & CAMEL_GW_MESSAGE_JUNK)) /*marked a message junk*/
+				move_to_junk (folder, info, ex);
+			else if (flags & CAMEL_GW_MESSAGE_JUNK) /*message was marked as junk, now unjunk*/ 
+				move_to_mailbox (folder, info, ex);
+
+			/*summary changed: start everything all over again*/
+			count = camel_folder_summary_count (folder->summary);
+			camel_message_info_free (info);
+			info = NULL;
+			i=0;
+			continue;
+		}
 
 		if (gw_info && (gw_info->info.flags & CAMEL_MESSAGE_FOLDER_FLAGGED)) {
 			do_flags_diff (&diff, gw_info->server_flags, gw_info->info.flags);
@@ -641,6 +657,7 @@ groupwise_sync (CamelFolder *folder, gbo
 	}
 	
 	camel_folder_summary_save (folder->summary);
+	g_mutex_unlock (mutex);
 
 }
 
@@ -731,6 +748,7 @@ update_update (CamelSession *session, Ca
 	int cursor = 0;
 	const char *position = E_GW_CURSOR_POSITION_END;
 	gboolean done;
+	
 
 	status = e_gw_connection_create_cursor (m->cnc, m->container_id, "id", NULL, &cursor);
 	if (status != E_GW_CONNECTION_STATUS_OK) {
@@ -1513,11 +1531,18 @@ static void
 gw_update_all_items ( CamelFolder *folder, GSList *item_list, CamelException *ex) 
 {
 	CamelGroupwiseFolder *gw_folder = CAMEL_GROUPWISE_FOLDER (folder);
-	GPtrArray *summary = camel_folder_get_summary (folder);
+	GPtrArray *summary;
 	int index = 0;
 	GSList *item_ids = NULL, *l = NULL;
 	CamelFolderChangeInfo *changes = NULL;
 
+	if (!mutex)
+		mutex = g_mutex_new ();
+
+	if (!g_mutex_try_lock (mutex))
+		return;
+
+	summary = camel_folder_get_summary (folder);
 	changes = camel_folder_change_info_new ();
 	/*item_ids : List of ids from the summary*/
 	while (index < summary->len) {
@@ -1533,17 +1558,21 @@ gw_update_all_items ( CamelFolder *folde
 		temp = g_slist_find_custom (item_list, (const char *)item_ids->data, (GCompareFunc) string_cmp);
 		if (!temp) {
 			//g_print ("Deleting:%s\n", (const char *)item_ids->data);
-			CAMEL_GROUPWISE_FOLDER_LOCK (folder, cache_lock);
-			camel_folder_summary_remove_uid (folder->summary, (const char *)item_ids->data);
-			camel_data_cache_remove(gw_folder->cache, "cache", (const char *)item_ids->data, ex);
-			camel_folder_change_info_remove_uid(changes, (const char *)item_ids->data);
-			CAMEL_GROUPWISE_FOLDER_UNLOCK (folder, cache_lock);
+			if (camel_folder_summary_uid (folder->summary, (const char *)item_ids->data)) {
+				
+				CAMEL_GROUPWISE_FOLDER_LOCK (folder, cache_lock);
+				camel_folder_summary_remove_uid (folder->summary, (const char *)item_ids->data);
+				camel_data_cache_remove(gw_folder->cache, "cache", (const char *)item_ids->data, ex);
+				camel_folder_change_info_remove_uid(changes, (const char *)item_ids->data);
+				CAMEL_GROUPWISE_FOLDER_UNLOCK (folder, cache_lock);
+			}
 		} 
 	}
 	camel_object_trigger_event (folder, "folder_changed", changes);
 
 	camel_folder_free_summary (folder, summary);
 	g_slist_free (l);
+	g_mutex_unlock (mutex);
 }
 
 static void
@@ -1706,6 +1735,7 @@ groupwise_transfer_messages_to (CamelFol
 			char **tmp;
 			guint32 temp_flags = 0;
 			CamelGroupwiseMessageInfo *src_info = (CamelGroupwiseMessageInfo *)camel_folder_summary_uid (source->summary, (const char*)uids->pdata[index]);
+			CamelGroupwiseMessageInfo *dest_info;
 			
 			/* we don't want to blindly copy the info: reset some flags not suitable for destination*/
 			if (!strcmp(source->full_name, JUNK_FOLDER))
@@ -1713,7 +1743,7 @@ groupwise_transfer_messages_to (CamelFol
 			else if (!strcmp(destination->full_name, JUNK_FOLDER))
 				camel_folder_set_message_flags (source, old_uid, CAMEL_MESSAGE_JUNK, CAMEL_GW_MESSAGE_JUNK);
 
-			CamelGroupwiseMessageInfo *dest_info = (CamelGroupwiseMessageInfo *)camel_message_info_clone((CamelMessageInfo *)src_info);
+			dest_info = (CamelGroupwiseMessageInfo *)camel_message_info_clone((CamelMessageInfo *)src_info);
 			tmp = g_strsplit (old_uid, ":", -1);
 			dest_info->info.uid = g_strdup_printf ("%s:%s",tmp[0], dest_container_id);
 			temp_flags = camel_folder_get_message_flags (source, (const char *)uids->pdata[index]);
@@ -1725,6 +1755,11 @@ groupwise_transfer_messages_to (CamelFol
 				camel_folder_set_message_flags (source, (const char *)uids->pdata[index],
 						CAMEL_MESSAGE_DELETED, CAMEL_MESSAGE_DELETED);
 
+				/*remove the item from summary and cache*/
+				CAMEL_GROUPWISE_FOLDER_LOCK (source, cache_lock);
+				camel_folder_summary_remove (source->summary, (CamelMessageInfo *)src_info);
+				camel_data_cache_remove((CAMEL_GROUPWISE_FOLDER (source))->cache, "cache", (char *)uids->pdata[index], ex);
+				CAMEL_GROUPWISE_FOLDER_UNLOCK (source, cache_lock);
 			}
 		} else {
 			g_warning ("Warning!! Could not move item : %s\n", (char *)uids->pdata[index]);


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