From 3a2860a4612ee86f992e4073b72a8b3ea5259e95 Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Tue, 14 Sep 2021 17:27:56 +0200 Subject: [PATCH 1/2] gs-plugin-loader: Introduce gs_plugin_action_finished() GsPlugin function Plugins can define it, to be notified when a plugin action is finished by all plugins. --- lib/gs-plugin-loader.c | 12 ++++++++++++ lib/gs-plugin-vfuncs.h | 14 ++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c index 4d5240c32..a16ac03c4 100644 --- a/lib/gs-plugin-loader.c +++ b/lib/gs-plugin-loader.c @@ -183,6 +183,8 @@ typedef gboolean (*GsPluginGetLangPacksFunc) (GsPlugin *plugin, const gchar *locale, GCancellable *cancellable, GError **error); +typedef void (*GsPluginActionFinishedFunc) (GsPlugin *plugin, + GsPluginAction action); /* async helper */ @@ -1230,6 +1232,16 @@ gs_plugin_loader_run_results (GsPluginLoaderHelper *helper, return FALSE; } + /* Notify plugins about the action being finished */ + for (guint i = 0; i < plugin_loader->plugins->len; i++) { + GsPlugin *plugin = g_ptr_array_index (plugin_loader->plugins, i); + gpointer func = gs_plugin_get_symbol (plugin, "gs_plugin_action_finished"); + if (func != NULL) { + GsPluginActionFinishedFunc action_finished_func = func; + action_finished_func (plugin, action); + } + } + #ifdef HAVE_SYSPROF if (plugin_loader->sysprof_writer != NULL) { g_autofree gchar *sysprof_name = NULL; diff --git a/lib/gs-plugin-vfuncs.h b/lib/gs-plugin-vfuncs.h index 23b7829db..14f19d669 100644 --- a/lib/gs-plugin-vfuncs.h +++ b/lib/gs-plugin-vfuncs.h @@ -933,4 +933,18 @@ gboolean gs_plugin_disable_repo (GsPlugin *plugin, GsApp *repo, GCancellable *cancellable, GError **error); + +/** + * gs_plugin_action_finished: + * @plugin: a #GsPlugin + * @action: a #GsPluginAction + * + * This is a notification function, calls after the @action is finished, + * which means every plugin had been called with this @action. + * + * Since: 41.1 + **/ +void gs_plugin_action_finished (GsPlugin *plugin, + GsPluginAction action); + G_END_DECLS -- GitLab From 5263d7b18e9fc801fd7380a382eea3da36992b0a Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Tue, 14 Sep 2021 17:29:52 +0200 Subject: [PATCH 2/2] gs-plugin-appstream: Invalidate the silo after install/update/remove is finished These actions can cause changes on the disk, which are not always noticed by the XbSilo, thus explicitly request a refresh of the XbSilo to ensure an up-to-date state is used by this plugin. Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1422 --- plugins/core/gs-plugin-appstream.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/plugins/core/gs-plugin-appstream.c b/plugins/core/gs-plugin-appstream.c index f7b3ae428..b01cb1b4c 100644 --- a/plugins/core/gs-plugin-appstream.c +++ b/plugins/core/gs-plugin-appstream.c @@ -30,6 +30,7 @@ struct GsPluginData { XbSilo *silo; GRWLock silo_lock; GSettings *settings; + gboolean needs_refresh; }; void @@ -516,10 +517,12 @@ gs_plugin_appstream_check_silo (GsPlugin *plugin, reader_locker = g_rw_lock_reader_locker_new (&priv->silo_lock); /* everything is okay */ - if (priv->silo != NULL && xb_silo_is_valid (priv->silo)) + if (priv->silo != NULL && !priv->needs_refresh && xb_silo_is_valid (priv->silo)) return TRUE; g_clear_pointer (&reader_locker, g_rw_lock_reader_locker_free); + priv->needs_refresh = FALSE; + /* drat! silo needs regenerating */ writer_locker = g_rw_lock_writer_locker_new (&priv->silo_lock); g_clear_object (&priv->silo); @@ -1135,3 +1138,15 @@ gs_plugin_refresh (GsPlugin *plugin, { return gs_plugin_appstream_check_silo (plugin, cancellable, error); } + +void +gs_plugin_action_finished (GsPlugin *plugin, + GsPluginAction action) +{ + if (action == GS_PLUGIN_ACTION_INSTALL || + action == GS_PLUGIN_ACTION_REMOVE || + action == GS_PLUGIN_ACTION_UPDATE) { + GsPluginData *priv = gs_plugin_get_data (plugin); + priv->needs_refresh = TRUE; + } +} -- GitLab