[gnome-software] trivial: Do not call _setup() multiple times on the same plugin
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] trivial: Do not call _setup() multiple times on the same plugin
- Date: Thu, 23 Feb 2017 15:51:29 +0000 (UTC)
commit 6c903520097fec00ce18a5f6abefd6fefbeb8f1d
Author: Richard Hughes <richard hughsie com>
Date: Thu Feb 23 15:13:48 2017 +0000
trivial: Do not call _setup() multiple times on the same plugin
We can just do destroy->init->setup to get the state back to known values,
which then exposes other assumptions in the self test program.
src/gs-plugin-loader.c | 57 ++++++++++++++++++++++++++++---------
src/gs-plugin-loader.h | 1 +
src/gs-plugin-private.h | 1 +
src/gs-plugin.c | 15 ++++++++++
src/gs-self-test.c | 6 ++--
src/plugins/gs-flatpak.c | 4 +-
src/plugins/gs-plugin-appstream.c | 12 --------
7 files changed, 65 insertions(+), 31 deletions(-)
---
diff --git a/src/gs-plugin-loader.c b/src/gs-plugin-loader.c
index 9e4bafa..430ecb8 100644
--- a/src/gs-plugin-loader.c
+++ b/src/gs-plugin-loader.c
@@ -3499,6 +3499,17 @@ gs_plugin_loader_plugin_dir_changed_cb (GFileMonitor *monitor,
gs_plugin_loader_add_event (plugin_loader, event);
}
+void
+gs_plugin_loader_clear_caches (GsPluginLoader *plugin_loader)
+{
+ GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
+ for (guint i = 0; i < priv->plugins->len; i++) {
+ GsPlugin *plugin = g_ptr_array_index (priv->plugins, i);
+ gs_plugin_cache_invalidate (plugin);
+ }
+ gs_app_list_remove_all (priv->global_cache);
+}
+
/**
* gs_plugin_loader_setup_again:
* @plugin_loader: a #GsPluginLoader
@@ -3510,20 +3521,38 @@ void
gs_plugin_loader_setup_again (GsPluginLoader *plugin_loader)
{
GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
- g_autoptr(GsPluginLoaderJob) job = gs_plugin_loader_job_new (plugin_loader);
- job->action = GS_PLUGIN_ACTION_SETUP;
- job->failure_flags = GS_PLUGIN_FAILURE_FLAGS_NO_CONSOLE;
- job->function_name = "gs_plugin_setup";
- for (guint i = 0; i < priv->plugins->len; i++) {
- GsPlugin *plugin = g_ptr_array_index (priv->plugins, i);
- g_autoptr(GError) error_local = NULL;
- if (!gs_plugin_get_enabled (plugin))
- continue;
- if (!gs_plugin_loader_call_vfunc (job, plugin, NULL, NULL,
- NULL, &error_local)) {
- g_warning ("resetup of %s failed: %s",
- gs_plugin_get_name (plugin),
- error_local->message);
+ const gchar *func_names[] = {
+ "gs_plugin_destroy",
+ "gs_plugin_initialize",
+ "gs_plugin_setup",
+ NULL };
+
+ /* clear global cache */
+ gs_plugin_loader_clear_caches (plugin_loader);
+
+ /* remove any events */
+ gs_plugin_loader_remove_events (plugin_loader);
+
+ /* call in order */
+ for (guint j = 0; func_names[j] != NULL; j++) {
+ for (guint i = 0; i < priv->plugins->len; i++) {
+ g_autoptr(GError) error_local = NULL;
+ g_autoptr(GsPluginLoaderJob) job = gs_plugin_loader_job_new (plugin_loader);
+ GsPlugin *plugin = g_ptr_array_index (priv->plugins, i);
+ if (!gs_plugin_get_enabled (plugin))
+ continue;
+ job->action = GS_PLUGIN_ACTION_SETUP;
+ job->failure_flags = GS_PLUGIN_FAILURE_FLAGS_NO_CONSOLE;
+ job->function_name = func_names[j];
+ if (!gs_plugin_loader_call_vfunc (job, plugin, NULL, NULL,
+ NULL, &error_local)) {
+ g_warning ("resetup of %s failed: %s",
+ gs_plugin_get_name (plugin),
+ error_local->message);
+ break;
+ }
+ if (g_strcmp0 (func_names[j], "gs_plugin_destroy") == 0)
+ gs_plugin_clear_data (plugin);
}
}
}
diff --git a/src/gs-plugin-loader.h b/src/gs-plugin-loader.h
index 279be97..f1ed607 100644
--- a/src/gs-plugin-loader.h
+++ b/src/gs-plugin-loader.h
@@ -279,6 +279,7 @@ GsApp *gs_plugin_loader_app_create (GsPluginLoader
*plugin_loader,
/* only useful from the self tests */
void gs_plugin_loader_setup_again (GsPluginLoader *plugin_loader);
+void gs_plugin_loader_clear_caches (GsPluginLoader *plugin_loader);
G_END_DECLS
diff --git a/src/gs-plugin-private.h b/src/gs-plugin-private.h
index eda4b8d..a5d8b92 100644
--- a/src/gs-plugin-private.h
+++ b/src/gs-plugin-private.h
@@ -37,6 +37,7 @@ GsPlugin *gs_plugin_create (const gchar *filename,
const gchar *gs_plugin_error_to_string (GsPluginError error);
const gchar *gs_plugin_action_to_string (GsPluginAction action);
+void gs_plugin_clear_data (GsPlugin *plugin);
void gs_plugin_action_start (GsPlugin *plugin,
gboolean exclusive);
void gs_plugin_action_stop (GsPlugin *plugin);
diff --git a/src/gs-plugin.c b/src/gs-plugin.c
index e4fdc2e..9f3639e 100644
--- a/src/gs-plugin.c
+++ b/src/gs-plugin.c
@@ -259,6 +259,21 @@ gs_plugin_alloc_data (GsPlugin *plugin, gsize sz)
}
/**
+ * gs_plugin_clear_data:
+ * @plugin: a #GsPlugin
+ *
+ * Clears and resets the private data. Only run this from the self tests.
+ **/
+void
+gs_plugin_clear_data (GsPlugin *plugin)
+{
+ GsPluginPrivate *priv = gs_plugin_get_instance_private (plugin);
+ if (priv->data == NULL)
+ return;
+ g_clear_pointer (&priv->data, g_free);
+}
+
+/**
* gs_plugin_action_start:
* @plugin: a #GsPlugin
* @exclusive: if the plugin action should be performed exclusively
diff --git a/src/gs-self-test.c b/src/gs-self-test.c
index 94a9262..b6cb01a 100644
--- a/src/gs-self-test.c
+++ b/src/gs-self-test.c
@@ -521,8 +521,8 @@ gs_plugin_loader_error_func (GsPluginLoader *plugin_loader)
g_autoptr(GPtrArray) events = NULL;
g_autoptr(GsApp) app = NULL;
- /* remove previous errors */
- gs_plugin_loader_remove_events (plugin_loader);
+ /* drop all caches */
+ gs_plugin_loader_setup_again (plugin_loader);
/* suppress this */
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
@@ -1468,7 +1468,7 @@ gs_plugin_loader_flatpak_app_missing_runtime_func (GsPluginLoader *plugin_loader
GS_PLUGIN_FAILURE_FLAGS_NO_CONSOLE,
NULL,
&error);
- g_assert_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_FAILED);
+ g_assert_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_NOT_SUPPORTED);
g_assert (!ret);
g_clear_error (&error);
g_assert_cmpint (gs_app_get_state (app), ==, AS_APP_STATE_AVAILABLE);
diff --git a/src/plugins/gs-flatpak.c b/src/plugins/gs-flatpak.c
index 5c9ba06..df4232c 100644
--- a/src/plugins/gs-flatpak.c
+++ b/src/plugins/gs-flatpak.c
@@ -1376,8 +1376,8 @@ refine_origin_from_installation (GsFlatpak *self,
gs_app_set_origin (app, remote_name);
return TRUE;
}
- g_warning ("failed to find remote %s: %s",
- remote_name, error_local->message);
+ g_debug ("failed to find remote %s: %s",
+ remote_name, error_local->message);
}
g_set_error (error,
GS_PLUGIN_ERROR,
diff --git a/src/plugins/gs-plugin-appstream.c b/src/plugins/gs-plugin-appstream.c
index bb5bee4..b608584 100644
--- a/src/plugins/gs-plugin-appstream.c
+++ b/src/plugins/gs-plugin-appstream.c
@@ -254,18 +254,6 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
guint i;
g_autoptr(GHashTable) origins = NULL;
- /* setup_again from the tests */
- as_store_remove_all (priv->store);
- if (priv->app_hash_old != NULL) {
- if (priv->app_hash_old != NULL)
- g_hash_table_unref (priv->app_hash_old);
- priv->app_hash_old = NULL;
- }
- if (priv->store_changed_id != 0) {
- g_signal_handler_disconnect (priv->store, priv->store_changed_id);
- priv->store_changed_id = 0;
- }
-
/* Parse the XML */
if (g_getenv ("GNOME_SOFTWARE_PREFER_LOCAL") != NULL) {
as_store_set_add_flags (priv->store,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]