[gnome-software/wip/jrocha/fix-runtime-extensions-update: 2/2] flatpak: Use "list of related apps for install" when updating an app



commit ad4971b6b1337df342a3b090bd25b8c39d6c6048
Author: Joaquim Rocha <jrocha endlessm com>
Date:   Tue Nov 7 15:25:05 2017 +0100

    flatpak: Use "list of related apps for install" when updating an app
    
    When updating an app, it gets the "list of apps for install" because
    those apps should also be be updated together with their main app.
    However, that list only contains apps that aren't yet installed (it's
    kind of expected from the name, but it's not what the code in
    gs_flatpak_update_app expects), so it means that once installed, related
    apps would never be updated together with the main app.
    
    These changes introduce a gs_flatpak_get_list_for_update which will
    return a list of the mentioned related apps that need to be installed or
    updated. This new function is used when updating an app, and the rest of
    the logic was already in place, so it means that when updating an app it
    will also update its related apps.

 plugins/flatpak/gs-flatpak.c | 71 ++++++++++++++++++++++++++++++--------------
 1 file changed, 49 insertions(+), 22 deletions(-)
---
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index 21d2ab84..cc497d77 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -2568,8 +2568,11 @@ gs_flatpak_refine_runtime_for_install (GsFlatpak *self,
 }
 
 static GsAppList *
-gs_flatpak_get_list_for_install (GsFlatpak *self, GsApp *app,
-                                GCancellable *cancellable, GError **error)
+gs_flatpak_get_list_for_install_or_update (GsFlatpak *self,
+                                          GsApp *app,
+                                          gboolean is_update,
+                                          GCancellable *cancellable,
+                                          GError **error)
 {
        GsApp *runtime;
        g_autofree gchar *ref = NULL;
@@ -2577,6 +2580,7 @@ gs_flatpak_get_list_for_install (GsFlatpak *self, GsApp *app,
        g_autoptr(GPtrArray) xrefs_installed = NULL;
        g_autoptr(GHashTable) hash_installed = NULL;
        g_autoptr(GsAppList) list = gs_app_list_new ();
+       g_autofree gchar *app_ref = NULL;
 
        /* get the list of installed apps */
        xrefs_installed = flatpak_installation_list_installed_refs (self->installation,
@@ -2640,35 +2644,58 @@ gs_flatpak_get_list_for_install (GsFlatpak *self, GsApp *app,
                /* already installed? */
                app_tmp = gs_flatpak_create_app (self, FLATPAK_REF (xref_related));
                ref_display = gs_flatpak_app_get_ref_display (app_tmp);
-               if (g_hash_table_contains (hash_installed, ref_display)) {
+               if (!is_update && g_hash_table_contains (hash_installed, ref_display)) {
                        g_debug ("not adding related %s as already installed", ref_display);
-               } else {
-                       gs_app_set_origin (app_tmp, gs_app_get_origin (app));
-                       g_debug ("adding related %s for install", ref_display);
-
-                       if (!gs_plugin_refine_item_state (self, app_tmp, cancellable, &error_local)) {
-                               if (g_error_matches (error_local, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
-                                       g_propagate_error (error, g_steal_pointer (&error_local));
-                                       return NULL;
-                               }
-                               g_warning ("Failed to refine %s when getting the list of apps to "
-                                          "install: %s; not adding the app...",
-                                          gs_app_get_unique_id (app_tmp),
-                                          error_local->message);
-                               continue;
-                       }
+                       continue;
+               }
 
-                       gs_app_list_add (list, app_tmp);
+               gs_app_set_origin (app_tmp, gs_app_get_origin (app));
+               if (!gs_plugin_refine_item_state (self, app_tmp, cancellable, &error_local)) {
+                       if (g_error_matches (error_local, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+                               g_propagate_error (error, g_steal_pointer (&error_local));
+                               return NULL;
+                       }
+                       g_warning ("Failed to refine %s when getting the list of apps to "
+                                  "install/update: %s; not adding the app...",
+                                  gs_app_get_unique_id (app_tmp),
+                                  error_local->message);
+                       continue;
                }
+               if (is_update && !gs_app_is_updatable (app_tmp)) {
+                       g_debug ("not adding related %s as it's not updatable", ref_display);
+                       continue;
+               }
+               g_debug ("adding related %s for install/update", ref_display);
+               gs_app_list_add (list, app_tmp);
        }
 
-       /* add the original app last unless it's a proxy app */
-       if (!gs_app_has_quirk (app, AS_APP_QUIRK_IS_PROXY))
+       /* add the original app last unless it's already installed or is a proxy app */
+       app_ref = gs_flatpak_app_get_ref_display (app);
+       if (!gs_app_has_quirk (app, AS_APP_QUIRK_IS_PROXY) &&
+           !g_hash_table_contains (hash_installed, app_ref))
                gs_app_list_add (list, app);
 
        return g_steal_pointer (&list);
 }
 
+static GsAppList *
+gs_flatpak_get_list_for_install (GsFlatpak *self,
+                                GsApp *app,
+                                GCancellable *cancellable,
+                                GError **error)
+{
+       return gs_flatpak_get_list_for_install_or_update (self, app, FALSE, cancellable, error);
+}
+
+static GsAppList *
+gs_flatpak_get_list_for_update (GsFlatpak *self,
+                               GsApp *app,
+                               GCancellable *cancellable,
+                               GError **error)
+{
+       return gs_flatpak_get_list_for_install_or_update (self, app, TRUE, cancellable, error);
+}
+
 gboolean
 gs_flatpak_app_remove (GsFlatpak *self,
                       GsApp *app,
@@ -3054,7 +3081,7 @@ gs_flatpak_update_app (GsFlatpak *self,
        }
 
        /* get the list of apps to process */
-       list = gs_flatpak_get_list_for_install (self, app, cancellable, error);
+       list = gs_flatpak_get_list_for_update (self, app, cancellable, error);
        if (list == NULL) {
                g_prefix_error (error, "failed to get related refs: ");
                gs_app_set_state_recover (app);


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