[gnome-software: 1/3] flatpak: Don't disable the plugin if an installation setup fails
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 1/3] flatpak: Don't disable the plugin if an installation setup fails
- Date: Tue, 26 Jan 2021 13:55:36 +0000 (UTC)
commit cad143e73dfd9896412075a3c346a151711529f0
Author: Joaquim Rocha <jrocha endlessm com>
Date: Fri May 18 16:52:29 2018 +0200
flatpak: Don't disable the plugin if an installation setup fails
When setting up the Flatpak plugin, if a Flatpak Installation had a
problem (corrupt repository's config, etc.), then the plugin got
disabled and just logged the error. This is a problem because:
1) The user is not informed that an error occurred;
2) The user won't be able to use e.g. the system installation even if
only the user's installation failed.
This patch changes that so that an error event (in-app banner) is shown
to the user, and allows the plugin to continue enabled unless all of
the installations have failed.
plugins/flatpak/gs-plugin-flatpak.c | 72 ++++++++++++++++++++++++++++---------
1 file changed, 55 insertions(+), 17 deletions(-)
---
diff --git a/plugins/flatpak/gs-plugin-flatpak.c b/plugins/flatpak/gs-plugin-flatpak.c
index d6f0bccc..66c0f84d 100644
--- a/plugins/flatpak/gs-plugin-flatpak.c
+++ b/plugins/flatpak/gs-plugin-flatpak.c
@@ -18,6 +18,7 @@
#include <config.h>
#include <flatpak.h>
+#include <glib/gi18n.h>
#include <gnome-software.h>
#include <glib/gi18n-lib.h>
@@ -115,6 +116,20 @@ gs_plugin_flatpak_add_installation (GsPlugin *plugin,
return TRUE;
}
+static void
+gs_plugin_flatpak_report_warning (GsPlugin *plugin,
+ GError **error)
+{
+ g_autoptr(GsPluginEvent) event = gs_plugin_event_new ();
+ g_assert (error != NULL);
+ if (*error != NULL && (*error)->domain != GS_PLUGIN_ERROR)
+ gs_flatpak_error_convert (error);
+ gs_plugin_event_set_error (event, *error);
+ gs_plugin_event_add_flag (event,
+ GS_PLUGIN_EVENT_FLAG_WARNING);
+ gs_plugin_report_event (plugin, event);
+}
+
gboolean
gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
{
@@ -125,17 +140,26 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
/* we use a permissions helper to elevate privs */
if (priv->has_system_helper && priv->destdir_for_tests == NULL) {
+ g_autoptr(GError) error_local = NULL;
g_autoptr(GPtrArray) installations = NULL;
- installations = flatpak_get_system_installations (cancellable, error);
+
+ installations = flatpak_get_system_installations (cancellable,
+ &error_local);
if (installations == NULL) {
- gs_flatpak_error_convert (error);
- return FALSE;
- }
- for (guint i = 0; i < installations->len; i++) {
- FlatpakInstallation *installation = g_ptr_array_index (installations, i);
- if (!gs_plugin_flatpak_add_installation (plugin, installation,
- cancellable, error)) {
- return FALSE;
+ gs_plugin_flatpak_report_warning (plugin, &error_local);
+ } else {
+ for (guint i = 0; i < installations->len; i++) {
+ FlatpakInstallation *installation =
+ g_ptr_array_index (installations, i);
+ if (!gs_plugin_flatpak_add_installation (plugin,
+ installation,
+ cancellable,
+ &error_local)) {
+ gs_plugin_flatpak_report_warning (plugin,
+ &error_local);
+ g_clear_error (&error_local);
+ continue;
+ }
}
}
}
@@ -164,17 +188,31 @@ gs_plugin_setup (GsPlugin *plugin, GCancellable *cancellable, GError **error)
/* per-user installations always available when not in self tests */
if (priv->destdir_for_tests == NULL) {
g_autoptr(FlatpakInstallation) installation = NULL;
- installation = flatpak_installation_new_user (cancellable, error);
- if (installation == NULL) {
- gs_flatpak_error_convert (error);
- return FALSE;
- }
- if (!gs_plugin_flatpak_add_installation (plugin, installation,
- cancellable, error)) {
- return FALSE;
+ g_autoptr(GError) error_local = NULL;
+
+ installation = flatpak_installation_new_user (cancellable,
+ &error_local);
+ if (installation != NULL)
+ gs_plugin_flatpak_add_installation (plugin, installation,
+ cancellable, &error_local);
+
+ if (error_local != NULL) {
+ /* if some error happened, report it as an event, but
+ * do not return it, otherwise it will disable the whole
+ * plugin (meaning that support for Flatpak will not be
+ * possible even if a system installation is working) */
+ gs_plugin_flatpak_report_warning (plugin, &error_local);
}
}
+ if (priv->flatpaks->len == 0) {
+ /* when no installation has been loaded, return the error so the
+ * plugin gets disabled */
+ g_set_error (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_FAILED,
+ "Failed to load any Flatpak installations");
+ return FALSE;
+ }
+
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]