[evolution-patches] patch to fix problems with folder name (camel-groupwise)



hi,

The attached patch fixes various bugs regarding the folder name
conflicts in groupwise provider. Now we can handle duplicate folder
names properly if they are at different hierarchies.
 
I have changed the code to use full name of the folder, wherever we have
to get the info about the folder only with the help of its name, so that
we don't end up having name conflicts.

Thanks,
Vivek Jain
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/providers/groupwise/ChangeLog,v
retrieving revision 1.62
diff -u -p -r1.62 ChangeLog
--- ChangeLog	7 Jul 2005 09:17:47 -0000	1.62
+++ ChangeLog	11 Jul 2005 06:22:07 -0000
@@ -1,3 +1,30 @@
+2005-07-11 Vivek Jain <jvivek novell com>
+	
+	* camel-groupwise-store.[ch] :
+	(gw_get_path) : removed
+	* camel-groupwise-store.c: 
+	(groupwise_get_folder_info): Changed the name hash. Now
+	it stores full names of the folders
+	(groupwise_rename_folder):
+	(groupwise_delete_folder):
+	(groupwise_create_folder):
+	(groupwise_get_folder) :
+	use full name of the folder to perform any operation, when 
+	folder name is to be taken from name_hash
+	(groupwise_build_folder_info): we don't need to call gw_get_path
+	use full name passed directly
+	
+	* camel-groupwise-folder.c : 
+	(groupwise_transfer_messages_to): 
+	(groupwise_append_message):
+	(groupwise_expunge):
+	(groupwise_sync):
+	(groupwise_folder_get_message):
+	(groupwise_folder_get_message):
+	(groupwise_refresh_folder):
+	(groupwise_update_summary):
+	use full_name in container id lookup 
+
 2005-07-07  Parthasarathi Susarla <sparthasarathi novell com>
 	
 	* camel-groupwise-folder.c: (gw_update_summary):
Index: camel-groupwise-store.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/providers/groupwise/camel-groupwise-store.c,v
retrieving revision 1.48
diff -u -p -r1.48 camel-groupwise-store.c
--- camel-groupwise-store.c	7 Jul 2005 07:10:59 -0000	1.48
+++ camel-groupwise-store.c	11 Jul 2005 06:22:08 -0000
@@ -518,8 +518,7 @@ groupwise_get_folder (CamelStore *store,
 	CamelSession *session = camel_service_get_session (CAMEL_SERVICE (store));
 	CamelGroupwiseSummary *summary;
 	char *time_string = NULL;
-	char *storage_path, *folder_dir, *temp_str,*container_id ;
-	const char *temp_name;
+	char *storage_path, *folder_dir, *container_id ;
 	EGwConnectionStatus status ;
 	GList *list = NULL ;
 	gboolean done = FALSE ;
@@ -555,16 +554,8 @@ groupwise_get_folder (CamelStore *store,
 			return NULL;
 		}
 	}
-	
-	temp_name = folder_name ;
-	temp_str = strrchr(folder_name,'/') ;
-	if(temp_str == NULL) {
-		container_id = 	g_strdup (g_hash_table_lookup (priv->name_hash, g_strdup(folder_name))) ;
-	}
-	else {
-		temp_str++ ;
-		container_id = 	g_strdup (g_hash_table_lookup (priv->name_hash, g_strdup(temp_str))) ;
-	}
+
+	container_id = 	g_strdup (g_hash_table_lookup (priv->name_hash, g_strdup(folder_name))) ;
 
 	folder = camel_gw_folder_new (store, folder_name, folder_dir, ex) ;
 	if (!folder) {
@@ -674,7 +665,7 @@ static CamelFolderInfo *
 groupwise_build_folder_info(CamelGroupwiseStore *gw_store, const char *parent_name, const char *folder_name)
 {
 	CamelURL *url ;
-	const char *name, *full_name ;
+	const char *name;
 	CamelFolderInfo *fi ;
 	CamelGroupwiseStorePrivate *priv = gw_store->priv ;
 
@@ -683,22 +674,14 @@ groupwise_build_folder_info(CamelGroupwi
 	fi->unread = 0 ;
 	fi->total = 0 ;
 
-	
-	
-	if (parent_name)
-		if (strlen(parent_name) > 0) {
-			full_name = gw_get_path (gw_store, parent_name) ;
-			fi->full_name = g_strconcat(full_name,"/",g_strdup(folder_name), NULL) ;
-		} else
-			fi->full_name = g_strdup (folder_name) ;
-	else {
-		full_name = gw_get_path (gw_store, folder_name) ;
-		if (full_name)
-			fi->full_name = g_strdup (full_name) ;
+	if (parent_name) {
+		if (strlen(parent_name) > 0) 
+			fi->full_name = g_strconcat(parent_name,"/",g_strdup(folder_name), NULL) ;
 		else
-			fi->full_name = g_strdup(folder_name) ;
-	}
-
+			fi->full_name = g_strdup (folder_name) ;
+	} else 
+		fi->full_name = g_strdup(folder_name) ;
+ 
 	url = camel_url_new(priv->base_url,NULL) ;
 	g_free(url->path) ;
 	url->path = g_strdup_printf("/%s", fi->full_name) ;
@@ -810,7 +793,7 @@ groupwise_get_folder_info (CamelStore *s
 	GPtrArray *folders;
 	GList *folder_list = NULL, *temp_list = NULL ;
 	const char *url, *top_folder, *temp_url ;
-	char *temp_str = NULL, *folder_real = NULL ;
+	char *folder_real = NULL ;
 	CamelFolderInfo *info = NULL ;
 	struct _store_folder_refresh *msg;
 
@@ -834,12 +817,7 @@ groupwise_get_folder_info (CamelStore *s
 		top_folder = "folders" ;
 		top = "" ;
 	} else {
-		temp_str = strrchr (top, '/') ;
-		if (temp_str) {
-			temp_str++ ;
-			top_folder = g_hash_table_lookup (priv->name_hash, temp_str) ;	
-		} else
-			top_folder = g_hash_table_lookup (priv->name_hash, top) ;
+		top_folder = g_hash_table_lookup (priv->name_hash, top) ;
 		/* 'top' is a valid path, but doesnt have a container id
 		 *  return NULL */
 		if (!top_folder)
@@ -882,8 +860,6 @@ groupwise_get_folder_info (CamelStore *s
 
 		/*id_hash returns the name for a given container id*/
 		g_hash_table_insert (priv->id_hash, g_strdup(id), g_strdup(name)) ; 
-		/*name_hash returns the container id given the name */
-		g_hash_table_insert (priv->name_hash, g_strdup(name), g_strdup(id)) ;
 		/*parent_hash returns the parent container id, given an id*/
 		g_hash_table_insert (priv->parent_hash, g_strdup(id), g_strdup(parent)) ;
 
@@ -897,6 +873,7 @@ groupwise_get_folder_info (CamelStore *s
 		EGwContainer *container = E_GW_CONTAINER (folder_list->data) ;
 		EGwContainerType type = e_gw_container_get_container_type (container) ;
 		const char *name = e_gw_container_get_name (container) ;
+		const char *id = e_gw_container_get_id (container);
 
 		if (e_gw_container_is_root (container)) 
 			continue ;
@@ -953,6 +930,9 @@ groupwise_get_folder_info (CamelStore *s
 			fi->name =  fi->full_name = g_strdup (name);
 			fi->uri = g_strconcat (url, "", name, NULL) ;
 		}
+		
+		/*name_hash returns the container id given the name */
+		g_hash_table_insert (priv->name_hash, g_strdup(fi->full_name), g_strdup(id)) ;
 
 		if (e_gw_container_get_is_shared_to_me (container))
                         fi->flags |= CAMEL_FOLDER_SHARED_TO_ME;
@@ -979,14 +959,9 @@ groupwise_get_folder_info (CamelStore *s
 	/*Thread stuff ends*/
 	g_free ((char *)url) ;
 	if ( (top != NULL) && (folders->len == 0)) {
-		/*temp_str already contains the value if any*/
-		if (temp_str) {
-			CAMEL_SERVICE_UNLOCK (store, connect_lock);
-			return groupwise_build_folder_info (groupwise_store, NULL, temp_str ) ;
-		} else {
-			CAMEL_SERVICE_UNLOCK (store, connect_lock);
-			return groupwise_build_folder_info (groupwise_store, NULL, top ) ;
-		}
+		CAMEL_SERVICE_UNLOCK (store, connect_lock);
+		return groupwise_build_folder_info (groupwise_store, NULL, top ) ;
+
 	}
 	info = camel_folder_info_build (folders, top, '/', TRUE) ;
 	g_ptr_array_free (folders, TRUE) ;
@@ -995,6 +970,7 @@ groupwise_get_folder_info (CamelStore *s
 	camel_groupwise_store_summary_add_from_full(groupwise_store->summary, folder_real, '/') ;
 	camel_store_summary_save ((CamelStoreSummary *)groupwise_store->summary) ;
 	CAMEL_SERVICE_UNLOCK (store, connect_lock);
+
 	return info ;
 }
 
@@ -1042,7 +1018,7 @@ groupwise_create_folder(CamelStore *stor
 	CamelGroupwiseStore *groupwise_store = CAMEL_GROUPWISE_STORE (store);
 	CamelGroupwiseStorePrivate  *priv = groupwise_store->priv;
 	CamelFolderInfo *root = NULL ;
-	char *parent_id , *child_container_id, *temp_parent = NULL;
+	char *parent_id , *child_container_id;
 	int status;
 	
 	if (((CamelOfflineStore *) store)->state == CAMEL_OFFLINE_STORE_NETWORK_UNAVAIL) {
@@ -1053,14 +1029,9 @@ groupwise_create_folder(CamelStore *stor
 	if(parent_name == NULL)
 		parent_name = "" ;
 
-	if (parent_name && (strlen(parent_name) > 0) ) {
-		temp_parent = strrchr (parent_name,'/') ;
-		if (temp_parent && temp_parent[0]) {
-			temp_parent++ ;
-			parent_id = g_hash_table_lookup (priv->name_hash, g_strdup(temp_parent)) ;
-		} else
-			parent_id = g_hash_table_lookup (priv->name_hash, g_strdup(parent_name)) ;
-	} else
+	if (parent_name && (strlen(parent_name) > 0) ) 
+		parent_id = g_hash_table_lookup (priv->name_hash, g_strdup(parent_name)) ;
+	else
 		parent_id = "" ;
 
 	if (!E_IS_GW_CONNECTION( priv->cnc)) {
@@ -1076,7 +1047,7 @@ groupwise_create_folder(CamelStore *stor
 		camel_store_summary_save((CamelStoreSummary *)groupwise_store->summary);
 
 		g_hash_table_insert (priv->id_hash, g_strdup(child_container_id), g_strdup(folder_name)) ; 
-		g_hash_table_insert (priv->name_hash, g_strdup(folder_name), g_strdup(child_container_id)) ;
+		g_hash_table_insert (priv->name_hash, g_strdup(root->full_name), g_strdup(child_container_id)) ;
 		g_hash_table_insert (priv->parent_hash, g_strdup(child_container_id), g_strdup(parent_id)) ;
 
 		camel_object_trigger_event (CAMEL_OBJECT (store), "folder_created", root);
@@ -1093,7 +1064,6 @@ groupwise_delete_folder(CamelStore *stor
 	CamelGroupwiseStore *groupwise_store = CAMEL_GROUPWISE_STORE (store);
 	CamelGroupwiseStorePrivate  *priv = groupwise_store->priv;
 	EGwConnectionStatus status ;
-	const char *name = NULL;
 	const char * container ; 
 	
 	if (((CamelOfflineStore *) store)->state == CAMEL_OFFLINE_STORE_NETWORK_UNAVAIL) {
@@ -1101,26 +1071,17 @@ groupwise_delete_folder(CamelStore *stor
 		return;
 	}
 	
-	name = strrchr (folder_name, '/') ;
-	if (name) {
-		name++ ;
-		container = g_hash_table_lookup (priv->name_hash, name) ;
-	} else
-		container = g_hash_table_lookup (priv->name_hash, folder_name) ;
+	container = g_hash_table_lookup (priv->name_hash, folder_name) ;
 
 	CAMEL_SERVICE_LOCK (store, connect_lock) ;
-	
+
 	status = e_gw_connection_remove_item (priv->cnc, container, container) ;
 
 	if (status == E_GW_CONNECTION_STATUS_OK) {
 		groupwise_forget_folder(groupwise_store,folder_name,ex) ;
-		
+
 		g_hash_table_remove (priv->id_hash, container) ;
-		
-		if (name)
-			g_hash_table_remove (priv->name_hash, name) ;
-		else 
-			g_hash_table_remove (priv->name_hash, folder_name) ;
+		g_hash_table_remove (priv->name_hash, folder_name) ;
 		
 		g_hash_table_remove (priv->parent_hash, container) ;
 	}
@@ -1140,20 +1101,15 @@ groupwise_rename_folder(CamelStore *stor
 	CamelGroupwiseStorePrivate  *priv = groupwise_store->priv;
 	char *oldpath, *newpath, *storepath ;
 	const char *container_id ;
-	char *temp_old = NULL, *temp_new = NULL ;
+	char *temp_new = NULL ;
 	
 	if (((CamelOfflineStore *) store)->state == CAMEL_OFFLINE_STORE_NETWORK_UNAVAIL) {
 		camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot rename GroupWise folders in offline mode."));
 		return;
 	}
 	CAMEL_SERVICE_LOCK (store, connect_lock) ;
-	temp_old = strrchr (old_name,'/') ;
-	if (temp_old) {
-		temp_old++ ;
-		container_id = camel_groupwise_store_container_id_lookup (groupwise_store, temp_old) ;
-	} else
-		container_id = camel_groupwise_store_container_id_lookup (groupwise_store, old_name) ;
-
+	
+	container_id = camel_groupwise_store_container_id_lookup (groupwise_store, old_name) ;
 	temp_new = strrchr (new_name, '/') ;
 	if (temp_new) 
 		temp_new++ ;
@@ -1170,12 +1126,8 @@ groupwise_rename_folder(CamelStore *stor
 
 	g_hash_table_replace (priv->id_hash, g_strdup(container_id), g_strdup(temp_new)) ;
 
-        g_hash_table_insert (priv->name_hash, g_strdup(temp_new), g_strdup(container_id)) ;
-	
-	if (temp_old)
-		g_hash_table_remove (priv->name_hash, g_strdup(temp_old)) ;
-	else
-		g_hash_table_remove (priv->name_hash, g_strdup(old_name)) ;
+	g_hash_table_insert (priv->name_hash, g_strdup(new_name), g_strdup(container_id)) ;
+	g_hash_table_remove (priv->name_hash, g_strdup(old_name)) ;
 	/*FIXME:Update all the id in the parent_hash*/
 
 	storepath = g_strdup_printf ("%s/folders", priv->storage_path) ;
@@ -1285,33 +1237,6 @@ storage_path_lookup (CamelGroupwiseStore
 	return priv->storage_path ;
 }
 
-const char *
-gw_get_path (CamelGroupwiseStore *gw_store, const char *folder_name)
-{
-	CamelGroupwiseStorePrivate *priv = gw_store->priv ;
-
-	const char *str = g_strdup (folder_name) ;
-	gchar *container_id = NULL, *temp_parent = NULL, *temp = NULL ;
-
-
-	container_id = g_hash_table_lookup (priv->name_hash, folder_name) ;
-
-	if (container_id)
-		temp_parent = g_hash_table_lookup (priv->parent_hash, container_id) ;
-	else 
-		temp_parent = NULL ;
-	while (temp_parent) {
-		temp = g_hash_table_lookup (priv->id_hash, temp_parent ) ;
-		if (temp == NULL) {
-			break ;
-		}	
-		str = g_strconcat ( temp, "/", str, NULL) ;
-
-		temp_parent = g_hash_table_lookup (priv->parent_hash, temp_parent) ;
-	} 
-
-	return str ;
-}
 
 static void
 free_hash (gpointer key, gpointer value, gpointer data)
Index: camel-groupwise-folder.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/providers/groupwise/camel-groupwise-folder.c,v
retrieving revision 1.57
diff -u -p -r1.57 camel-groupwise-folder.c
--- camel-groupwise-folder.c	7 Jul 2005 09:17:47 -0000	1.57
+++ camel-groupwise-folder.c	11 Jul 2005 06:22:09 -0000
@@ -99,7 +99,7 @@ groupwise_folder_get_message( CamelFolde
 	CamelGroupwiseStore *gw_store = CAMEL_GROUPWISE_STORE(folder->parent_store);
 	CamelGroupwiseStorePrivate  *priv = gw_store->priv;
 	CamelGroupwiseMessageInfo *mi = NULL;
-	char *temp_name, *folder_name, *container_id;
+	char *container_id;
 	EGwConnectionStatus status;
 	EGwConnection *cnc;
 	EGwItem *item;
@@ -155,18 +155,8 @@ groupwise_folder_get_message( CamelFolde
 		return NULL;
 	}
 
+	container_id =  g_strdup (camel_groupwise_store_container_id_lookup (gw_store, folder->full_name)) ;
 
-	folder_name = g_strdup(folder->name);
-	temp_name = strrchr (folder_name,'/');
-	if(temp_name == NULL) {
-		container_id =  g_strdup (camel_groupwise_store_container_id_lookup (gw_store, folder_name));
-	}
-	else {
-		temp_name++;
-		container_id =  g_strdup (camel_groupwise_store_container_id_lookup (gw_store, temp_name));
-	}
-
-	g_free (folder_name);
 	//XXX:free container_id
 	
 	cnc = cnc_lookup (priv);
@@ -579,8 +569,8 @@ 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->name);
-	
+	container_id =  camel_groupwise_store_container_id_lookup (gw_store, folder->full_name) ;
+
 	CAMEL_SERVICE_LOCK (gw_store, connect_lock);
 
 	count = camel_folder_summary_count (folder->summary);
@@ -789,9 +779,11 @@ groupwise_refresh_folder(CamelFolder *fo
 		return;
 	}
 
-	container_id = g_strdup (camel_groupwise_store_container_id_lookup (gw_store, folder->name));
+	g_print ("\n the full name is=%s\n", folder->full_name);	
+	container_id = g_strdup (camel_groupwise_store_container_id_lookup (gw_store, folder->full_name)) ;
+
 	if (!container_id) {
-		g_error ("\nERROR - Container id not present. Cannot refresh info\n");
+		g_error ("\nERROR - Container id not present. Cannot refresh info for %s\n", folder->full_name);
 		return;
 	}
 
@@ -927,7 +919,7 @@ gw_update_summary ( CamelFolder *folder,
 
 	msg = g_ptr_array_new ();
 	changes = camel_folder_change_info_new ();
-	container_id = g_strdup (camel_groupwise_store_container_id_lookup (gw_store, folder->name));
+	container_id = g_strdup (camel_groupwise_store_container_id_lookup (gw_store, folder->full_name));
 	if (!container_id) {
 		g_error ("\nERROR - Container id not present. Cannot refresh info\n");
 		return;
@@ -1313,7 +1305,8 @@ groupwise_append_message (CamelFolder *f
 	}
 	CAMEL_SERVICE_LOCK (folder->parent_store, connect_lock);
 	/*Get the container id*/
-	container_id = camel_groupwise_store_container_id_lookup (gw_store, folder->name);
+	container_id = camel_groupwise_store_container_id_lookup (gw_store, folder->full_name) ;
+
 	/* FIXME Separate To/CC/BCC? */
 	recipients = CAMEL_ADDRESS (camel_internet_address_new ());
 	camel_address_cat (recipients, CAMEL_ADDRESS (camel_mime_message_get_recipients (message, CAMEL_RECIPIENT_TYPE_TO)));
@@ -1407,11 +1400,11 @@ groupwise_transfer_messages_to (CamelFol
 		*transferred_uids = NULL;
 
 	if (delete_originals) 
-		source_container_id = camel_groupwise_store_container_id_lookup (gw_store, source->name);
+		source_container_id = camel_groupwise_store_container_id_lookup (gw_store, source->full_name) ;
 	else
 		source_container_id = NULL;
-	dest_container_id = camel_groupwise_store_container_id_lookup (gw_store, destination->name);
-
+	dest_container_id = camel_groupwise_store_container_id_lookup (gw_store, destination->full_name) ;
+	
 	CAMEL_SERVICE_LOCK (source->parent_store, connect_lock);
 	/* check for offline operation */
 	if (offline->state == CAMEL_OFFLINE_STORE_NETWORK_UNAVAIL) {
@@ -1499,7 +1492,7 @@ groupwise_expunge (CamelFolder *folder, 
 
 	cnc = cnc_lookup (priv);
 	
-	container_id =  g_strdup (camel_groupwise_store_container_id_lookup (groupwise_store, folder->name));
+	container_id =  g_strdup (camel_groupwise_store_container_id_lookup (groupwise_store, folder->full_name)) ;
 
 	max = camel_folder_summary_count (folder->summary);
 	for (i = 0; i < max; i++) {


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