[evolution-data-server/openismus-work-master] EBookBackendFile: Don't overwrite UIDs on incomming/new contacts.



commit 37b8f3c53f2ba82ee2e826affa7e73bdf322ded0
Author: Tristan Van Berkom <tristanvb openismus com>
Date:   Fri Jan 18 15:53:46 2013 +0900

    EBookBackendFile: Don't overwrite UIDs on incomming/new contacts.
    
      o Only assign a generated UID if the new contact does not have any
      o If the UID already exists in the SQLite at creation time, then
        report an E_CLIENT_ERROR_QUERY_REFUSED error.

 addressbook/backends/file/e-book-backend-file.c |   29 ++++++++++++++++------
 1 files changed, 21 insertions(+), 8 deletions(-)
---
diff --git a/addressbook/backends/file/e-book-backend-file.c b/addressbook/backends/file/e-book-backend-file.c
index 62b89a8..ffe9be1 100644
--- a/addressbook/backends/file/e-book-backend-file.c
+++ b/addressbook/backends/file/e-book-backend-file.c
@@ -718,9 +718,14 @@ do_create (EBookBackendFile *bf,
 		EContact        *contact;
 
 		vcard_req = (const gchar *) l->data;
+		contact = e_contact_new_from_vcard (vcard_req);
 
-		id      = e_book_backend_file_create_unique_id ();
-		contact = e_contact_new_from_vcard_with_uid (vcard_req, id);
+		/* Preserve original UID, create a unique UID if needed */
+		if (e_contact_get_const (contact, E_CONTACT_UID) == NULL) {
+			id = e_book_backend_file_create_unique_id ();
+			e_contact_set (contact, E_CONTACT_UID, id);
+			g_free (id);
+		}
 
 		rev = e_contact_get_const (contact, E_CONTACT_REV);
 		if (!(rev && *rev))
@@ -728,8 +733,6 @@ do_create (EBookBackendFile *bf,
 
 		status = maybe_transform_vcard_for_photo (bf, NULL, contact, perror);
 
-		g_free (id);
-
 		if (status != STATUS_ERROR) {
 
 			/* Contact was added successfully, add it to the local list */
@@ -749,14 +752,23 @@ do_create (EBookBackendFile *bf,
 
 	if (status != STATUS_ERROR) {
 
-		if (!e_book_backend_sqlitedb_add_contacts (bf->priv->sqlitedb,
+		if (!e_book_backend_sqlitedb_new_contacts (bf->priv->sqlitedb,
 							   SQLITEDB_FOLDER_ID,
 							   slist, FALSE,
 							   &local_error)) {
 
 			g_warning ("Failed to add contacts: %s", local_error->message);
-			g_propagate_error (perror, local_error);
 
+			if (g_error_matches (local_error,
+					     E_BOOK_SDB_ERROR,
+					     E_BOOK_SDB_ERROR_CONSTRAINT)) {
+				g_set_error (perror, E_CLIENT_ERROR,
+					     E_CLIENT_ERROR_QUERY_REFUSED,
+					     _("Conflicting UIDs found in added contacts"));
+				g_clear_error (&local_error);
+			} else
+				g_propagate_error (perror, local_error);
+ 
 			status = STATUS_ERROR;
 		}
 	}
@@ -969,9 +981,10 @@ e_book_backend_file_modify_contacts (EBookBackendSync *backend,
 		}
 
 		/* Update summary as well */
-		if (!e_book_backend_sqlitedb_add_contacts (bf->priv->sqlitedb,
+		if (!e_book_backend_sqlitedb_new_contacts (bf->priv->sqlitedb,
 							   SQLITEDB_FOLDER_ID,
-							   modified_contacts, FALSE, &local_error)) {
+							   modified_contacts, TRUE,
+							   &local_error)) {
 			g_warning ("Failed to modify contacts: %s", local_error->message);
 			g_propagate_error (perror, local_error);
 



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