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



commit 60f695ee77a0c3a894e640da2fd5a9a0e9da3475
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 | 64 ++++++++++++++++++++++++++++++--------------
 1 file changed, 44 insertions(+), 20 deletions(-)
---
diff --git a/plugins/flatpak/gs-flatpak.c b/plugins/flatpak/gs-flatpak.c
index c6dc4b3a..635f5ccf 100644
--- a/plugins/flatpak/gs-flatpak.c
+++ b/plugins/flatpak/gs-flatpak.c
@@ -2569,8 +2569,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;
@@ -2641,26 +2644,29 @@ 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 */
@@ -2670,6 +2676,24 @@ gs_flatpak_get_list_for_install (GsFlatpak *self, GsApp *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,
@@ -3080,7 +3104,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]