[gnome-software/1486-gs-repos-dialog-call-refresh-on-repository-setup-change: 184/184] plugins: Refresh internal caches on repository enable/install
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/1486-gs-repos-dialog-call-refresh-on-repository-setup-change: 184/184] plugins: Refresh internal caches on repository enable/install
- Date: Thu, 14 Oct 2021 06:27:47 +0000 (UTC)
commit 0bd589fddf5bca8208ac455d35f252e736d1521a
Author: Milan Crha <mcrha redhat com>
Date: Thu Oct 14 08:24:11 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 | 48 ++++++++++++++++++++++++++++++-
plugins/packagekit/gs-plugin-packagekit.c | 36 +++++++++++++++++++++++
plugins/rpm-ostree/gs-plugin-rpm-ostree.c | 10 ++++++-
4 files changed, 96 insertions(+), 18 deletions(-)
---
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index 88bb69a72..d61998a09 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -1623,9 +1623,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),
@@ -1636,8 +1633,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
@@ -1671,17 +1666,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 81938ad57..f467e9339 100644
--- a/plugins/fwupd/gs-plugin-fwupd.c
+++ b/plugins/fwupd/gs-plugin-fwupd.c
@@ -1191,6 +1191,45 @@ gs_plugin_add_sources (GsPlugin *plugin,
return TRUE;
}
+static gboolean
+gs_plugin_fwupd_refresh_single_remote (GsPluginFwupd *self,
+ GsApp *repo,
+ guint cache_age,
+ GCancellable *cancellable,
+ GError **error)
+{
+ 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 (self->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 (self, remote, cache_age, cancellable, error))
+ return FALSE;
+ break;
+ }
+ }
+
+ return TRUE;
+}
+
gboolean
gs_plugin_enable_repo (GsPlugin *plugin,
GsApp *repo,
@@ -1207,7 +1246,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 (self, repo, TRUE, cancellable, error);
+ if (!gs_plugin_fwupd_modify_source (self, 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 (self, repo, 1, cancellable, NULL);
+
+ return TRUE;
}
gboolean
diff --git a/plugins/packagekit/gs-plugin-packagekit.c b/plugins/packagekit/gs-plugin-packagekit.c
index 31f50d1cd..e2dbde686 100644
--- a/plugins/packagekit/gs-plugin-packagekit.c
+++ b/plugins/packagekit/gs-plugin-packagekit.c
@@ -2588,6 +2588,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)
+{
+ GsPluginPackagekit *self = GS_PLUGIN_PACKAGEKIT (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 (&self->task_mutex);
+ /* cache age of 1 is user-initiated */
+ pk_client_set_background (PK_CLIENT (self->task), cache_age > 1);
+ pk_client_set_interactive (PK_CLIENT (self->task), gs_plugin_has_flags (plugin,
GS_PLUGIN_FLAGS_INTERACTIVE));
+ pk_client_set_cache_age (PK_CLIENT (self->task), cache_age);
+ /* refresh the metadata */
+ results = pk_client_refresh_cache (PK_CLIENT (self->task),
+ FALSE /* force */,
+ cancellable,
+ gs_packagekit_helper_cb, helper,
+ error);
+ g_mutex_unlock (&self->task_mutex);
+ if (!gs_plugin_packagekit_results_valid (results, error)) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
gboolean
gs_plugin_enable_repo (GsPlugin *plugin,
GsApp *repo,
@@ -2635,6 +2667,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 2175f06f9..273ccb181 100644
--- a/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
+++ b/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
@@ -2266,7 +2266,15 @@ gs_plugin_enable_repo (GsPlugin *plugin,
if (!gs_rpmostree_ref_proxies (self, &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]