[evolution-data-server/openismus-work] EBookBackendFile: Don't overwrite UIDs on incomming/new contacts.
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/openismus-work] EBookBackendFile: Don't overwrite UIDs on incomming/new contacts.
- Date: Fri, 18 Jan 2013 07:07:24 +0000 (UTC)
commit 6f0cf1d4ce712b9546bcb4a27e33fd21d782f655
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 5916dfb..39f6c53 100644
--- a/addressbook/backends/file/e-book-backend-file.c
+++ b/addressbook/backends/file/e-book-backend-file.c
@@ -719,9 +719,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))
@@ -729,8 +734,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;
}
}
@@ -972,9 +984,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]