[gnome-software/wip/mcrha/backport-to-gnome-40] flatpak: Remember applications to update when replacing by a parent application



commit f166f1f554fb18b0d79916950897eb2b1911ecb8
Author: Milan Crha <mcrha redhat com>
Date:   Mon May 24 16:08:46 2021 +0200

    flatpak: Remember applications to update when replacing by a parent application
    
    Runtimes can be hidden under other runtimes, but calling update on the parent
    runtime won't necessarily update also the child runtime, thus remember
    the reported ref to be updated by Flatpak and ask to update it together with
    the parent runtime.
    
    Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1252

 plugins/flatpak/gs-flatpak.c        |  2 ++
 plugins/flatpak/gs-plugin-flatpak.c | 45 +++++++++++++++++++++++++------------
 2 files changed, 33 insertions(+), 14 deletions(-)
---
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index faf245ca6..f58085dee 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -1686,6 +1686,8 @@ get_real_app_for_update (GsFlatpak *self,
                         "setting the latter's state instead.", gs_app_get_unique_id (app),
                         gs_app_get_unique_id (main_app));
                gs_app_set_state (main_app, GS_APP_STATE_UPDATABLE_LIVE);
+               /* Make sure the 'app' is not forgotten, it'll be added into the transaction later */
+               gs_app_add_related (main_app, app);
        }
 
        return main_app;
diff --git a/plugins/flatpak/gs-plugin-flatpak.c b/plugins/flatpak/gs-plugin-flatpak.c
index a6f23e446..364bc27d1 100644
--- a/plugins/flatpak/gs-plugin-flatpak.c
+++ b/plugins/flatpak/gs-plugin-flatpak.c
@@ -461,6 +461,36 @@ _ref_to_app (FlatpakTransaction *transaction, const gchar *ref, GsPlugin *plugin
        return gs_plugin_flatpak_find_app_by_ref (plugin, ref, NULL, NULL);
 }
 
+static void
+_group_apps_by_installation_recurse (GsPlugin *plugin,
+                                    GsAppList *list,
+                                    GHashTable *applist_by_flatpaks)
+{
+       if (!list)
+               return;
+
+       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);
+                       GsAppList *related_list;
+                       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);
+
+                       /* Add also related apps, which can be those recognized for update,
+                          while the 'app' is already up to date. */
+                       related_list = gs_app_get_related (app);
+                       _group_apps_by_installation_recurse (plugin, related_list, applist_by_flatpaks);
+               }
+       }
+}
+
 /*
  * Returns: (transfer full) (element-type GsFlatpak GsAppList):
  *  a map from GsFlatpak to non-empty lists of apps from @list associated
@@ -478,20 +508,7 @@ _group_apps_by_installation (GsPlugin *plugin,
                                                     (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);
-               }
-       }
+       _group_apps_by_installation_recurse (plugin, list, applist_by_flatpaks);
 
        return g_steal_pointer (&applist_by_flatpaks);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]