[folks] Fix a race condition in Tpf.PersonaStore



commit 853d7721b144153a3c1496c012b24e226999f440
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Thu Mar 24 16:11:09 2011 +0000

    Fix a race condition in Tpf.PersonaStore
    
    The /IndividualRetrieval/aggregator:add test can execute multiple calls to
    Tpf.PersonaStore.add_persona_from_details() with the same contact ID
    simultaneously. Since the change to use sets, the fact that only one
    of the adds is succeeding is no longer hidden by our use of GLib.List.
    
    This commit fixes the error handling in
    Tpf.PersonaStore.add_persona_from_details() to be more resilient to the
    contact already existing.
    
    Helps: bgo#640092

 backends/telepathy/lib/tpf-persona-store.vala |   47 ++++++++++++-------------
 1 files changed, 23 insertions(+), 24 deletions(-)
---
diff --git a/backends/telepathy/lib/tpf-persona-store.vala b/backends/telepathy/lib/tpf-persona-store.vala
index c3189c1..c9dab7a 100644
--- a/backends/telepathy/lib/tpf-persona-store.vala
+++ b/backends/telepathy/lib/tpf-persona-store.vala
@@ -1315,38 +1315,37 @@ public class Tpf.PersonaStore : Folks.PersonaStore
         }
     }
 
-  private async HashSet<Persona>? _create_personas_from_contact_ids (
+  private async HashSet<Persona> _create_personas_from_contact_ids (
       string[] contact_ids) throws GLib.Error
     {
-      if (contact_ids.length > 0)
-        {
-          GLib.List<TelepathyGLib.Contact> contacts =
-              yield this._ll.connection_get_contacts_by_id_async (
-                  this._conn, contact_ids, (uint[]) _contact_features);
+      var personas = new HashSet<Persona> ();
 
-          var personas = new HashSet<Persona> ();
-          unowned GLib.List<TelepathyGLib.Contact> l;
-          for (l = contacts; l != null; l = l.next)
-            {
-              var contact = l.data;
+      if (contact_ids.length == 0)
+        return personas;
 
-              debug ("Creating persona from contact '%s'", contact.identifier);
+      GLib.List<TelepathyGLib.Contact> contacts =
+          yield this._ll.connection_get_contacts_by_id_async (
+              this._conn, contact_ids, (uint[]) _contact_features);
 
-              var persona = this._add_persona_from_contact (contact, true);
-              if (persona != null)
-                personas.add (persona);
-            }
+      unowned GLib.List<TelepathyGLib.Contact> l;
+      for (l = contacts; l != null; l = l.next)
+        {
+          var contact = l.data;
 
-          if (personas.size > 0)
-            {
-              this.personas_changed (personas, new HashSet<Persona> (),
-                  null, null, 0);
-            }
+          debug ("Creating persona from contact '%s'", contact.identifier);
 
-          return personas;
+          var persona = this._add_persona_from_contact (contact, true);
+          if (persona != null)
+            personas.add (persona);
+        }
+
+      if (personas.size > 0)
+        {
+          this.personas_changed (personas, new HashSet<Persona> (),
+              null, null, 0);
         }
 
-      return null;
+      return personas;
     }
 
   private Tpf.Persona? _add_persona_from_contact (Contact contact,
@@ -1520,7 +1519,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore
           var personas = yield this._create_personas_from_contact_ids (
               contact_ids);
 
-          if (personas == null)
+          if (personas.size == 0)
             {
               /* the persona already existed */
               return null;



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