[evolution-data-server] source_registry_server_monitor_changed_cb: Reuse existing source



commit 3738cdcd1b26625ce1a005d0c24b8814c593a7a0
Author: Milan Crha <mcrha redhat com>
Date:   Thu Jun 18 17:50:27 2015 +0200

    source_registry_server_monitor_changed_cb: Reuse existing source
    
    When available, reuse existing source, thus all the changes are not
    done on an object which is immediately freed.

 libebackend/e-source-registry-server.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/libebackend/e-source-registry-server.c b/libebackend/e-source-registry-server.c
index 85c0ca6..61aa39a 100644
--- a/libebackend/e-source-registry-server.c
+++ b/libebackend/e-source-registry-server.c
@@ -424,9 +424,20 @@ source_registry_server_monitor_changed_cb (GFileMonitor *monitor,
        if (event_type == G_FILE_MONITOR_EVENT_CREATED) {
                ESource *source;
                GError *error = NULL;
+               gchar *uid;
+
+               uid = e_server_side_source_uid_from_file (file, NULL);
+               if (!uid)
+                       return;
 
-               /* it can return NULL source for hidden files */
-               source = e_server_side_source_new (server, file, &error);
+               source = e_source_registry_server_ref_source (server, uid);
+
+               g_free (uid);
+
+               if (!source) {
+                       /* it can return NULL source for hidden files */
+                       source = e_server_side_source_new (server, file, &error);
+               }
 
                if (!error && source) {
                        /* File monitors are only placed on directories
@@ -438,12 +449,13 @@ source_registry_server_monitor_changed_cb (GFileMonitor *monitor,
                                E_SERVER_SIDE_SOURCE (source), TRUE);
 
                        e_source_registry_server_add_source (server, source);
-                       g_object_unref (source);
                } else if (error) {
                        e_source_registry_server_load_error (
                                server, file, error);
                        g_error_free (error);
                }
+
+               g_clear_object (&source);
        }
 
        if (event_type == G_FILE_MONITOR_EVENT_DELETED) {


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