[gnome-software/wip/mcrha/m1024-to-gnome-41] plugins: Refresh internal caches on repository enable/install
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/mcrha/m1024-to-gnome-41] plugins: Refresh internal caches on repository enable/install
- Date: Thu, 21 Oct 2021 15:07:40 +0000 (UTC)
commit 507dce9cb2d7a7e9d1d3d9059283cc8a4ebc5aac
Author: Milan Crha <mcrha redhat com>
Date: Thu Oct 21 17:06:24 2021 +0200
plugins: Refresh internal caches on repository enable/install
When the plugin enables or installs a repository or a remote, let
it update also the internal caches, thus the data provided is accurate.
Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1486
plugins/flatpak/gs-flatpak.c | 20 +++----------
plugins/fwupd/gs-plugin-fwupd.c | 49 ++++++++++++++++++++++++++++++-
plugins/packagekit/gs-plugin-packagekit.c | 36 +++++++++++++++++++++++
plugins/rpm-ostree/gs-plugin-rpm-ostree.c | 9 +++++-
4 files changed, 96 insertions(+), 18 deletions(-)
---
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index 8edc78359..ffdb3424c 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -1618,9 +1618,6 @@ gs_flatpak_app_install_source (GsFlatpak *self,
GError **error)
{
g_autoptr(FlatpakRemote) xremote = NULL;
- #if FLATPAK_CHECK_VERSION(1, 4, 0)
- gboolean filter_changed = FALSE;
- #endif
xremote = flatpak_installation_get_remote_by_name (self->installation,
gs_app_get_id (app),
@@ -1631,8 +1628,6 @@ gs_flatpak_app_install_source (GsFlatpak *self,
flatpak_remote_set_disabled (xremote, FALSE);
if (gs_flatpak_app_get_file_kind (app) == GS_FLATPAK_APP_FILE_KIND_REPO) {
#if FLATPAK_CHECK_VERSION(1, 4, 0)
- g_autofree gchar *current_filter = flatpak_remote_get_filter (xremote);
- filter_changed = g_strcmp0 (current_filter, gs_flatpak_app_get_repo_filter (app)) !=
0;
flatpak_remote_set_filter (xremote, gs_flatpak_app_get_repo_filter (app));
flatpak_remote_set_description (xremote, gs_app_get_description (app));
#endif
@@ -1666,17 +1661,10 @@ gs_flatpak_app_install_source (GsFlatpak *self,
/* success */
gs_app_set_state (app, GS_APP_STATE_INSTALLED);
- #if FLATPAK_CHECK_VERSION(1, 4, 0)
- if (filter_changed) {
- g_autoptr(GError) local_error = NULL;
- const gchar *remote_name = flatpak_remote_get_name (xremote);
- if (!flatpak_installation_update_appstream_sync (self->installation, remote_name, NULL, NULL,
cancellable, &local_error) &&
- !g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
- g_warning ("Failed to update appstream data for flatpak remote '%s': %s",
- remote_name, local_error->message);
- }
- }
- #endif
+ /* This can fail silently, it's only to update necessary caches, to provide
+ * up-to-date information after the successful remote enable/install. */
+ gs_flatpak_refresh (self, 1, cancellable, NULL);
+
gs_plugin_repository_changed (self->plugin, app);
return TRUE;
diff --git a/plugins/fwupd/gs-plugin-fwupd.c b/plugins/fwupd/gs-plugin-fwupd.c
index 497c9dc2c..8dfc2deac 100644
--- a/plugins/fwupd/gs-plugin-fwupd.c
+++ b/plugins/fwupd/gs-plugin-fwupd.c
@@ -1183,6 +1183,46 @@ gs_plugin_add_sources (GsPlugin *plugin,
return TRUE;
}
+static gboolean
+gs_plugin_fwupd_refresh_single_remote (GsPlugin *plugin,
+ GsApp *repo,
+ guint cache_age,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ g_autoptr(GPtrArray) remotes = NULL;
+ g_autoptr(GError) error_local = NULL;
+ const gchar *remote_id;
+
+ remote_id = gs_app_get_metadata_item (repo, "fwupd::remote-id");
+ g_return_val_if_fail (remote_id != NULL, FALSE);
+
+ remotes = fwupd_client_get_remotes (priv->client, cancellable, &error_local);
+ if (remotes == NULL) {
+ g_debug ("No remotes found: %s", error_local ? error_local->message : "Unknown error");
+ if (g_error_matches (error_local, FWUPD_ERROR, FWUPD_ERROR_NOTHING_TO_DO) ||
+ g_error_matches (error_local, FWUPD_ERROR, FWUPD_ERROR_NOT_SUPPORTED) ||
+ g_error_matches (error_local, FWUPD_ERROR, FWUPD_ERROR_NOT_FOUND))
+ return TRUE;
+ g_propagate_error (error, g_steal_pointer (&error_local));
+ gs_plugin_fwupd_error_convert (error);
+ return FALSE;
+ }
+ for (guint i = 0; i < remotes->len; i++) {
+ FwupdRemote *remote = g_ptr_array_index (remotes, i);
+ if (g_strcmp0 (remote_id, fwupd_remote_get_id (remote)) == 0) {
+ if (fwupd_remote_get_enabled (remote) &&
+ fwupd_remote_get_kind (remote) != FWUPD_REMOTE_KIND_LOCAL &&
+ !gs_plugin_fwupd_refresh_remote (plugin, remote, cache_age, cancellable, error))
+ return FALSE;
+ break;
+ }
+ }
+
+ return TRUE;
+}
+
gboolean
gs_plugin_enable_repo (GsPlugin *plugin,
GsApp *repo,
@@ -1197,7 +1237,14 @@ gs_plugin_enable_repo (GsPlugin *plugin,
/* source -> remote */
g_return_val_if_fail (gs_app_get_kind (repo) == AS_COMPONENT_KIND_REPOSITORY, FALSE);
- return gs_plugin_fwupd_modify_source (plugin, repo, TRUE, cancellable, error);
+ if (!gs_plugin_fwupd_modify_source (plugin, repo, TRUE, cancellable, error))
+ return FALSE;
+
+ /* This can fail silently, it's only to update necessary caches, to provide
+ * up-to-date information after the successful repository enable/install. */
+ gs_plugin_fwupd_refresh_single_remote (plugin, repo, 1, cancellable, NULL);
+
+ return TRUE;
}
gboolean
diff --git a/plugins/packagekit/gs-plugin-packagekit.c b/plugins/packagekit/gs-plugin-packagekit.c
index 720dc1a49..ad00f8401 100644
--- a/plugins/packagekit/gs-plugin-packagekit.c
+++ b/plugins/packagekit/gs-plugin-packagekit.c
@@ -2572,6 +2572,38 @@ gs_plugin_app_upgrade_download (GsPlugin *plugin,
return TRUE;
}
+static gboolean
+gs_plugin_packagekit_refresh (GsPlugin *plugin,
+ GsApp *progress_app,
+ guint cache_age,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GsPluginData *priv = gs_plugin_get_data (plugin);
+ g_autoptr(GsPackagekitHelper) helper = gs_packagekit_helper_new (plugin);
+ g_autoptr(PkResults) results = NULL;
+
+ gs_packagekit_helper_set_progress_app (helper, progress_app);
+
+ g_mutex_lock (&priv->task_mutex);
+ /* cache age of 1 is user-initiated */
+ pk_client_set_background (PK_CLIENT (priv->task), cache_age > 1);
+ pk_client_set_interactive (PK_CLIENT (priv->task), gs_plugin_has_flags (plugin,
GS_PLUGIN_FLAGS_INTERACTIVE));
+ pk_client_set_cache_age (PK_CLIENT (priv->task), cache_age);
+ /* refresh the metadata */
+ results = pk_client_refresh_cache (PK_CLIENT (priv->task),
+ FALSE /* force */,
+ cancellable,
+ gs_packagekit_helper_cb, helper,
+ error);
+ g_mutex_unlock (&priv->task_mutex);
+ if (!gs_plugin_packagekit_results_valid (results, error)) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
gboolean
gs_plugin_enable_repo (GsPlugin *plugin,
GsApp *repo,
@@ -2619,6 +2651,10 @@ gs_plugin_enable_repo (GsPlugin *plugin,
/* state is known */
gs_app_set_state (repo, GS_APP_STATE_INSTALLED);
+ /* This can fail silently, it's only to update necessary caches, to provide
+ * up-to-date information after the successful repository enable/install. */
+ gs_plugin_packagekit_refresh (plugin, repo, 1, cancellable, NULL);
+
gs_plugin_repository_changed (plugin, repo);
return TRUE;
diff --git a/plugins/rpm-ostree/gs-plugin-rpm-ostree.c b/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
index 59b9f579c..4f6183aec 100644
--- a/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
+++ b/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
@@ -2249,7 +2249,14 @@ gs_plugin_enable_repo (GsPlugin *plugin,
if (!gs_rpmostree_ref_proxies (plugin, &os_proxy, &sysroot_proxy, cancellable, error))
return FALSE;
- return gs_rpmostree_repo_enable (plugin, repo, TRUE, os_proxy, sysroot_proxy, cancellable, error);
+ if (!gs_rpmostree_repo_enable (plugin, repo, TRUE, os_proxy, sysroot_proxy, cancellable, error))
+ return FALSE;
+
+ /* This can fail silently, it's only to update necessary caches, to provide
+ * up-to-date information after the successful repository enable/install. */
+ gs_plugin_refresh (plugin, 1, cancellable, NULL);
+
+ return TRUE;
}
gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]