diff options
author | Joaquim Rocha <jrocha@endlessm.com> | 2016-10-17 11:39:37 +0200 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2016-10-17 13:23:36 +0100 |
commit | 210988cc41ae81f1f59847475602be016dc5b12a (patch) | |
tree | 2c365f16f3c9c7b700f9110c8d6db79cc0bec662 | |
parent | ca73182b0ea7063e046e156dea494f3526431bdd (diff) | |
download | appstream-glib-210988cc41ae81f1f59847475602be016dc5b12a.tar.gz |
Process file changes when an attribute changes
When a file's permissions are changed this may mean that a file that was
previously unreadable can now be parsed so we should process files attribute
changes.
Also, when a file was changed, no processing of it occurred until a different
event type happened to the file (deletion, renaming, etc.). This could prevent
important changes to be processed. Update the tests for both issues.
Signed-off-by: Richard Hughes <richard@hughsie.com>
-rw-r--r-- | libappstream-glib/as-monitor.c | 10 | ||||
-rw-r--r-- | libappstream-glib/as-self-test.c | 4 |
2 files changed, 8 insertions, 6 deletions
diff --git a/libappstream-glib/as-monitor.c b/libappstream-glib/as-monitor.c index 799d869..bec94f7 100644 --- a/libappstream-glib/as-monitor.c +++ b/libappstream-glib/as-monitor.c @@ -282,12 +282,12 @@ as_monitor_process_pending_trigger_cb (gpointer user_data) } static void -as_monitor_process_pending_trigger (AsMonitor *monitor) +as_monitor_process_pending_trigger (AsMonitor *monitor, guint timeout_ms) { AsMonitorPrivate *priv = GET_PRIVATE (monitor); if (priv->pending_id) g_source_remove (priv->pending_id); - priv->pending_id = g_timeout_add (800, + priv->pending_id = g_timeout_add (timeout_ms, as_monitor_process_pending_trigger_cb, monitor); } @@ -336,7 +336,7 @@ as_monitor_file_changed_cb (GFileMonitor *mon, switch (event_type) { case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT: - as_monitor_process_pending (monitor); + as_monitor_process_pending_trigger (monitor, 50); break; case G_FILE_MONITOR_EVENT_CREATED: if (!is_temp) { @@ -345,7 +345,7 @@ as_monitor_file_changed_cb (GFileMonitor *mon, _g_ptr_array_str_add (priv->queue_temp, filename); } /* file monitors do not send CHANGES_DONE_HINT */ - as_monitor_process_pending_trigger (monitor); + as_monitor_process_pending_trigger (monitor, 800); break; case G_FILE_MONITOR_EVENT_DELETED: /* only emit notifications for files we know about */ @@ -356,11 +356,13 @@ as_monitor_file_changed_cb (GFileMonitor *mon, } break; case G_FILE_MONITOR_EVENT_CHANGED: + case G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED: /* if the file is not pending and not a temp file, add */ if (_g_ptr_array_str_find (priv->queue_add, filename) == NULL && _g_ptr_array_str_find (priv->queue_temp, filename) == NULL) { _g_ptr_array_str_add (priv->queue_changed, filename); } + as_monitor_process_pending_trigger (monitor, 800); break; case G_FILE_MONITOR_EVENT_RENAMED: /* a temp file that was just created and atomically diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c index 835ebd9..ddfb106 100644 --- a/libappstream-glib/as-self-test.c +++ b/libappstream-glib/as-self-test.c @@ -187,7 +187,7 @@ as_test_monitor_dir_func (void) as_test_loop_quit (); g_assert_cmpint (cnt_added, ==, 0); g_assert_cmpint (cnt_removed, ==, 0); - g_assert_cmpint (cnt_changed, ==, 0); + g_assert_cmpint (cnt_changed, ==, 1); /* delete it */ cnt_added = cnt_removed = cnt_changed = 0; @@ -283,7 +283,7 @@ as_test_monitor_file_func (void) as_test_loop_quit (); g_assert_cmpint (cnt_added, ==, 0); g_assert_cmpint (cnt_removed, ==, 0); - g_assert_cmpint (cnt_changed, ==, 0); + g_assert_cmpint (cnt_changed, ==, 1); /* delete it */ cnt_added = cnt_removed = cnt_changed = 0; |