[evolution-data-server] e-source-registry-server: Watch for changes to .source files and reload
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] e-source-registry-server: Watch for changes to .source files and reload
- Date: Fri, 19 Jun 2015 07:46:28 +0000 (UTC)
commit 16c8cb4ab02fcada017cf782ca7a8c27a25e882c
Author: Philip Withnall <philip withnall collabora co uk>
Date: Wed Jun 17 17:05:51 2015 +0100
e-source-registry-server: Watch for changes to .source files and reload
It is possible for evolution-source-registry to detect a newly-added
source file before the author of the file has written to it; the
registry will attempt to load the file, find it is invalid, and then
ignore it.
The registry should also listen for changes to files, and reload them
accordingly. This means that the source file will get reloaded after the
author has finished writing to it, and hence the source will get
created.
https://bugzilla.gnome.org/show_bug.cgi?id=751119
libebackend/e-source-registry-server.c | 45 ++++++++++++++++++++++++++++++++
1 files changed, 45 insertions(+), 0 deletions(-)
---
diff --git a/libebackend/e-source-registry-server.c b/libebackend/e-source-registry-server.c
index 1812d9e..ce364a0 100644
--- a/libebackend/e-source-registry-server.c
+++ b/libebackend/e-source-registry-server.c
@@ -421,6 +421,51 @@ source_registry_server_monitor_changed_cb (GFileMonitor *monitor,
GFileMonitorEvent event_type,
ESourceRegistryServer *server)
{
+ gchar *uri;
+
+ if (e_source_registry_debug_enabled ()) {
+ uri = g_file_get_uri (file);
+ e_source_registry_debug_print ("Handling file monitor event %u for URI: %s", event_type, uri);
+ g_free (uri);
+ }
+
+ if (event_type == G_FILE_MONITOR_EVENT_CHANGED ||
+ event_type == G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT) {
+ ESource *source;
+ gchar *uid;
+ GError *error = NULL;
+
+ uid = e_server_side_source_uid_from_file (file, NULL);
+
+ if (uid == NULL)
+ return;
+
+ source = e_source_registry_server_ref_source (server, uid);
+
+ g_free (uid);
+
+ /* If the source does not exist, create it; parsing may have
+ * failed when the file was originally created. This can happen
+ * if the file is created (empty), then e-source-registry-server
+ * detects it, then it’s populated and made valid.
+ *
+ * Otherwise, reload the file since it has changed. */
+ if (source == NULL) {
+ event_type = G_FILE_MONITOR_EVENT_CREATED;
+ } else if (!e_server_side_source_load (E_SERVER_SIDE_SOURCE (source), NULL, &error)) {
+ uri = g_file_get_uri (file);
+ g_warning ("Error reloading source ‘%s’: %s", uri, error->message);
+
+ g_free (uri);
+ g_error_free (error);
+ g_object_unref (source);
+
+ return;
+ }
+
+ g_object_unref (source);
+ }
+
if (event_type == G_FILE_MONITOR_EVENT_CREATED) {
ESource *source;
GError *error = NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]