[gnome-online-accounts] daemon: avoid ID collisions if accounts are created in the same second



commit 841bb9ba12ea9e8f7edc5deb1c29559baa2cb1f6
Author: Marco Barisione <marco barisione collabora co uk>
Date:   Wed Aug 14 15:04:39 2013 +0100

    daemon: avoid ID collisions if accounts are created in the same second
    
    https://bugzilla.gnome.org/show_bug.cgi?id=696267

 src/daemon/goadaemon.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/src/daemon/goadaemon.c b/src/daemon/goadaemon.c
index 2fb6173..aead6b1 100644
--- a/src/daemon/goadaemon.c
+++ b/src/daemon/goadaemon.c
@@ -703,14 +703,17 @@ goa_daemon_reload_configuration (GoaDaemon *daemon)
 static gchar *
 generate_new_id (GoaDaemon *daemon)
 {
+  static guint counter = 0;
   GDateTime *dt;
   gchar *ret;
 
   dt = g_date_time_new_now_local ();
-  ret = g_date_time_format (dt, "account_%s"); /* seconds since Epoch */
-  /* TODO: handle collisions */
+  ret = g_strdup_printf ("account_%" G_GINT64_FORMAT "_%u",
+                         g_date_time_to_unix (dt), /* seconds since Epoch */
+                         counter); /* avoids collisions */
   g_date_time_unref (dt);
 
+  counter++;
   return ret;
 }
 


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