[evolution-kolab] KolabMailAccess: elaborate on PIM folder existence check when creating



commit fe95bd1e7210034d73e7e06d11544313e0a9be44
Author: Christian Hilberg <hilberg kernelconcepts de>
Date:   Tue Sep 18 11:22:42 2012 +0200

    KolabMailAccess: elaborate on PIM folder existence check when creating
    
    * when creating a new PIM folder, we check whether it already
      exists
    * if so, we need to check whether it is of the same type which
      we are to create, in which case we're done (no-op)
    * if the folder creation request is for a different folder type
      than the one we already have, then that's an error

 src/libekolab/kolab-mail-access.c |   35 ++++++++++++++++++++++++++++++++++-
 1 files changed, 34 insertions(+), 1 deletions(-)
---
diff --git a/src/libekolab/kolab-mail-access.c b/src/libekolab/kolab-mail-access.c
index 80259c5..677a82c 100644
--- a/src/libekolab/kolab-mail-access.c
+++ b/src/libekolab/kolab-mail-access.c
@@ -3054,8 +3054,41 @@ kolab_mail_access_create_source (KolabMailAccess *self,
 		goto exit;
 	}
 
-	if (exists)
+	if (exists) {
+		KolabFolderSummary *summary = NULL;
+		KolabFolderTypeID type_id = KOLAB_FOLDER_TYPE_INVAL;
+
+		/* if the folder exists, we're done only if its
+		 * type matches the one we are to create (creation
+		 * is a no-op in this case)
+		 */
+
+		summary = kolab_mail_info_db_query_folder_summary (priv->infodb,
+		                                                   sourcename,
+		                                                   &tmp_err);
+		if (tmp_err != NULL)
+			goto exit;
+
+		type_id = kolab_folder_summary_get_uint_field (summary,
+		                                               KOLAB_FOLDER_SUMMARY_UINT_FIELD_FOLDER_TYPE);
+		kolab_folder_summary_free (summary);
+
+		/* if the type of the existing folder we are to create
+		 * matches the one already existing, we're done
+		 */
+		if (type_id == sourcetype)
+			goto exit;
+
+		/* folder exists, but required type does not match the
+		 * existing one, so we're not taking action
+		 */
+		g_set_error (&tmp_err,
+		             KOLAB_BACKEND_ERROR,
+		             KOLAB_BACKEND_ERROR_DATATYPE_KOLAB,
+		             _("A folder named '%s' already exists with a different folder type, cannot create"),
+		             sourcename);
 		goto exit;
+	}
 
 	/* create folder */
 	ok = mail_access_local_store (self,



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