Backport patches to fix a crash in gs_flatpak_get_installation

https://bugzilla.redhat.com/show_bug.cgi?id=1762689
This commit is contained in:
Kalev Lember 2019-10-18 13:59:19 +02:00
parent 3df71875f0
commit 9704cc1ded
3 changed files with 233 additions and 1 deletions

View File

@ -0,0 +1,109 @@
From cb926ab2645dbb548530c72f409d10736e584a2f Mon Sep 17 00:00:00 2001
From: Will Thompson <will@willthompson.co.uk>
Date: Fri, 27 Sep 2019 13:23:51 +0100
Subject: [PATCH 1/2] flatpak: factor out function to group by installation
I reworked it slightly to never put empty lists into the map, and to
make the caller iterate the hash table rather than looking up each
GsFlatpak * again. I think this is a bit clearer.
This will be reused in gs_plugin_download().
---
plugins/flatpak/gs-plugin-flatpak.c | 70 +++++++++++++++++++----------
1 file changed, 46 insertions(+), 24 deletions(-)
diff --git a/plugins/flatpak/gs-plugin-flatpak.c b/plugins/flatpak/gs-plugin-flatpak.c
index 007eab752..b4bc9a90d 100644
--- a/plugins/flatpak/gs-plugin-flatpak.c
+++ b/plugins/flatpak/gs-plugin-flatpak.c
@@ -405,6 +405,41 @@ _ref_to_app (FlatpakTransaction *transaction, const gchar *ref, GsPlugin *plugin
return gs_plugin_flatpak_find_app_by_ref (plugin, ref, NULL, NULL);
}
+/*
+ * Returns: (transfer full) (element-type GsFlatpak GsAppList):
+ * a map from GsFlatpak to non-empty lists of apps from @list associated
+ * with that installation.
+ */
+static GHashTable *
+_group_apps_by_installation (GsPlugin *plugin,
+ GsAppList *list)
+{
+ g_autoptr(GHashTable) applist_by_flatpaks = NULL;
+
+ /* list of apps to be handled by each flatpak installation */
+ applist_by_flatpaks = g_hash_table_new_full (g_direct_hash, g_direct_equal,
+ (GDestroyNotify) g_object_unref,
+ (GDestroyNotify) g_object_unref);
+
+ /* put each app into the correct per-GsFlatpak list */
+ for (guint i = 0; i < gs_app_list_length (list); i++) {
+ GsApp *app = gs_app_list_index (list, i);
+ GsFlatpak *flatpak = gs_plugin_flatpak_get_handler (plugin, app);
+ if (flatpak != NULL) {
+ GsAppList *list_tmp = g_hash_table_lookup (applist_by_flatpaks, flatpak);
+ if (list_tmp == NULL) {
+ list_tmp = gs_app_list_new ();
+ g_hash_table_insert (applist_by_flatpaks,
+ g_object_ref (flatpak),
+ list_tmp);
+ }
+ gs_app_list_add (list_tmp, app);
+ }
+ }
+
+ return g_steal_pointer (&applist_by_flatpaks);
+}
+
static FlatpakTransaction *
_build_transaction (GsPlugin *plugin, GsFlatpak *flatpak,
GCancellable *cancellable, GError **error)
@@ -759,34 +794,21 @@ gs_plugin_update (GsPlugin *plugin,
GCancellable *cancellable,
GError **error)
{
- GsPluginData *priv = gs_plugin_get_data (plugin);
g_autoptr(GHashTable) applist_by_flatpaks = NULL;
+ GHashTableIter iter;
+ gpointer key, value;
- /* list of apps to be handled by each flatpak installation */
- applist_by_flatpaks = g_hash_table_new_full (g_direct_hash, g_direct_equal,
- NULL, (GDestroyNotify) g_object_unref);
- for (guint i = 0; i < priv->flatpaks->len; i++) {
- g_hash_table_insert (applist_by_flatpaks,
- g_ptr_array_index (priv->flatpaks, i),
- gs_app_list_new ());
- }
+ /* build and run transaction for each flatpak installation */
+ applist_by_flatpaks = _group_apps_by_installation (plugin, list);
+ g_hash_table_iter_init (&iter, applist_by_flatpaks);
+ while (g_hash_table_iter_next (&iter, &key, &value)) {
+ GsFlatpak *flatpak = GS_FLATPAK (key);
+ GsAppList *list_tmp = GS_APP_LIST (value);
- /* put each app into the correct per-GsFlatpak list */
- for (guint i = 0; i < gs_app_list_length (list); i++) {
- GsApp *app = gs_app_list_index (list, i);
- GsFlatpak *flatpak = gs_plugin_flatpak_get_handler (plugin, app);
- if (flatpak != NULL) {
- GsAppList *list_tmp = g_hash_table_lookup (applist_by_flatpaks, flatpak);
- gs_app_list_add (list_tmp, app);
- }
- }
+ g_assert (GS_IS_FLATPAK (flatpak));
+ g_assert (list_tmp != NULL);
+ g_assert (gs_app_list_length (list_tmp) > 0);
- /* build and run transaction for each flatpak installation */
- for (guint j = 0; j < priv->flatpaks->len; j++) {
- GsFlatpak *flatpak = g_ptr_array_index (priv->flatpaks, j);
- GsAppList *list_tmp = GS_APP_LIST (g_hash_table_lookup (applist_by_flatpaks, flatpak));
- if (gs_app_list_length (list_tmp) == 0)
- continue;
if (!gs_plugin_flatpak_update (plugin, flatpak, list_tmp, cancellable, error))
return FALSE;
}
--
2.23.0

View File

@ -0,0 +1,118 @@
From ba103a6cbb27a4e01524a5c27f76266613f87936 Mon Sep 17 00:00:00 2001
From: Will Thompson <will@willthompson.co.uk>
Date: Fri, 27 Sep 2019 13:44:27 +0100
Subject: [PATCH 2/2] flatpak: download Flatpak updates in the correct
installation
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Unfortunately the fix in 3e1fe203b40248f571be2a804027acd8e23dc54e is
incomplete: the call to _build_transaction() later in the function also
assumes that 'flatpak' is non-NULL.
Apply the same fix as 12c3f646 to gs_plugin_download() as
opposed to gs_plugin_update() to group the apps by their flatpak
installation, and download each group independently.
---
plugins/flatpak/gs-plugin-flatpak.c | 74 +++++++++++++++--------------
1 file changed, 39 insertions(+), 35 deletions(-)
diff --git a/plugins/flatpak/gs-plugin-flatpak.c b/plugins/flatpak/gs-plugin-flatpak.c
index b4bc9a90d..aed246fac 100644
--- a/plugins/flatpak/gs-plugin-flatpak.c
+++ b/plugins/flatpak/gs-plugin-flatpak.c
@@ -475,51 +475,55 @@ gboolean
gs_plugin_download (GsPlugin *plugin, GsAppList *list,
GCancellable *cancellable, GError **error)
{
- GsFlatpak *flatpak = NULL;
- g_autoptr(FlatpakTransaction) transaction = NULL;
- g_autoptr(GsAppList) list_tmp = gs_app_list_new ();
+ g_autoptr(GHashTable) applist_by_flatpaks = NULL;
+ GHashTableIter iter;
+ gpointer key, value;
- /* not supported */
- for (guint i = 0; i < gs_app_list_length (list); i++) {
- GsApp *app = gs_app_list_index (list, i);
- flatpak = gs_plugin_flatpak_get_handler (plugin, app);
- if (flatpak != NULL)
- gs_app_list_add (list_tmp, app);
- }
- if (gs_app_list_length (list_tmp) == 0)
- return TRUE;
+ /* build and run transaction for each flatpak installation */
+ applist_by_flatpaks = _group_apps_by_installation (plugin, list);
+ g_hash_table_iter_init (&iter, applist_by_flatpaks);
+ while (g_hash_table_iter_next (&iter, &key, &value)) {
+ GsFlatpak *flatpak = GS_FLATPAK (key);
+ GsAppList *list_tmp = GS_APP_LIST (value);
+ g_autoptr(FlatpakTransaction) transaction = NULL;
- if (!gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_INTERACTIVE)) {
- g_autoptr(GError) error_local = NULL;
+ g_assert (GS_IS_FLATPAK (flatpak));
+ g_assert (list_tmp != NULL);
+ g_assert (gs_app_list_length (list_tmp) > 0);
- if (!gs_metered_block_app_list_on_download_scheduler (list_tmp, cancellable, &error_local)) {
- g_warning ("Failed to block on download scheduler: %s",
- error_local->message);
- g_clear_error (&error_local);
+ if (!gs_plugin_has_flags (plugin, GS_PLUGIN_FLAGS_INTERACTIVE)) {
+ g_autoptr(GError) error_local = NULL;
+
+ if (!gs_metered_block_app_list_on_download_scheduler (list_tmp, cancellable, &error_local)) {
+ g_warning ("Failed to block on download scheduler: %s",
+ error_local->message);
+ g_clear_error (&error_local);
+ }
}
- }
- /* build and run non-deployed transaction */
- transaction = _build_transaction (plugin, flatpak, cancellable, error);
- if (transaction == NULL) {
- gs_flatpak_error_convert (error);
- return FALSE;
- }
- flatpak_transaction_set_no_deploy (transaction, TRUE);
- for (guint i = 0; i < gs_app_list_length (list_tmp); i++) {
- GsApp *app = gs_app_list_index (list_tmp, i);
- g_autofree gchar *ref = NULL;
+ /* build and run non-deployed transaction */
+ transaction = _build_transaction (plugin, flatpak, cancellable, error);
+ if (transaction == NULL) {
+ gs_flatpak_error_convert (error);
+ return FALSE;
+ }
+ flatpak_transaction_set_no_deploy (transaction, TRUE);
+ for (guint i = 0; i < gs_app_list_length (list_tmp); i++) {
+ GsApp *app = gs_app_list_index (list_tmp, i);
+ g_autofree gchar *ref = NULL;
- ref = gs_flatpak_app_get_ref_display (app);
- if (!flatpak_transaction_add_update (transaction, ref, NULL, NULL, error)) {
+ ref = gs_flatpak_app_get_ref_display (app);
+ if (!flatpak_transaction_add_update (transaction, ref, NULL, NULL, error)) {
+ gs_flatpak_error_convert (error);
+ return FALSE;
+ }
+ }
+ if (!gs_flatpak_transaction_run (transaction, cancellable, error)) {
gs_flatpak_error_convert (error);
return FALSE;
}
}
- if (!gs_flatpak_transaction_run (transaction, cancellable, error)) {
- gs_flatpak_error_convert (error);
- return FALSE;
- }
+
return TRUE;
}
--
2.23.0

View File

@ -12,7 +12,7 @@
Name: gnome-software
Version: 3.34.1
Release: 5%{?dist}
Release: 6%{?dist}
Summary: A software center for GNOME
License: GPLv2+
@ -22,6 +22,8 @@ Source0: https://download.gnome.org/sources/gnome-software/3.34/%{name}-%{vers
# Backported from upstream
Patch1: 0001-Do-not-show-non-applications-in-the-installed-panel.patch
Patch2: 0001-Update-renamed-appstream-ids-for-GNOME-3.34.patch
Patch3: 0001-flatpak-factor-out-function-to-group-by-installation.patch
Patch4: 0002-flatpak-download-Flatpak-updates-in-the-correct-inst.patch
BuildRequires: gcc
BuildRequires: gettext
@ -224,6 +226,9 @@ desktop-file-validate %{buildroot}%{_datadir}/applications/*.desktop
%{_mandir}/man1/gnome-software-editor.1*
%changelog
* Fri Oct 18 2019 Kalev Lember <klember@redhat.com> - 3.34.1-6
- Backport patches to fix a crash in gs_flatpak_get_installation (#1762689)
* Mon Oct 14 2019 Kalev Lember <klember@redhat.com> - 3.34.1-5
- Update renamed appstream ids for GNOME 3.34