[gnome-software/wip/kalev/flatpak-fixes: 4/7] flatpak: Construct one big transaction for all updates



commit f9e654935c2cf9a626efaa0395cf959cd2bb9f49
Author: Kalev Lember <klember redhat com>
Date:   Wed Oct 3 13:45:58 2018 +0200

    flatpak: Construct one big transaction for all updates
    
    Instad of updating apps one by one, construct one big transaction that
    includes everything we need to update.
    
    This makes state keeping in gnome-software easier, as when we
    simplistically walk the update list and update one by one, sometimes
    updates depend on each other (app requires runtime) and we may end up in
    a case where the update is already installed.
    
    Furthermore, alex is saying that the CLI also makes one big transaction
    and doing so is more efficient as it avoids prunes and triggers between
    each update.

 plugins/flatpak/gs-plugin-flatpak.c | 55 ++++++++++++++++++++++++-------------
 1 file changed, 36 insertions(+), 19 deletions(-)
---
diff --git a/plugins/flatpak/gs-plugin-flatpak.c b/plugins/flatpak/gs-plugin-flatpak.c
index 6beabc73..dc29e9c9 100644
--- a/plugins/flatpak/gs-plugin-flatpak.c
+++ b/plugins/flatpak/gs-plugin-flatpak.c
@@ -2,7 +2,7 @@
  *
  * Copyright (C) 2016 Joaquim Rocha <jrocha endlessm com>
  * Copyright (C) 2016-2018 Richard Hughes <richard hughsie com>
- * Copyright (C) 2017 Kalev Lember <klember redhat com>
+ * Copyright (C) 2017-2018 Kalev Lember <klember redhat com>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -678,17 +678,22 @@ gs_plugin_app_install (GsPlugin *plugin,
 }
 
 gboolean
-gs_plugin_update_app (GsPlugin *plugin,
-                     GsApp *app,
-                     GCancellable *cancellable,
-                     GError **error)
+gs_plugin_update (GsPlugin *plugin,
+                  GsAppList *list,
+                  GCancellable *cancellable,
+                  GError **error)
 {
        GsFlatpak *flatpak;
        g_autoptr(FlatpakTransaction) transaction = NULL;
-       g_autofree gchar *ref = NULL;
+       g_autoptr(GsAppList) list_tmp = gs_app_list_new ();
 
        /* not supported */
-       flatpak = gs_plugin_flatpak_get_handler (plugin, app);
+       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 (flatpak == NULL)
                return TRUE;
 
@@ -698,14 +703,20 @@ gs_plugin_update_app (GsPlugin *plugin,
                gs_flatpak_error_convert (error);
                return FALSE;
        }
-       ref = gs_flatpak_app_get_ref_display (app);
-       if (!flatpak_transaction_add_update (transaction, ref, NULL, NULL, error)) {
-               g_prefix_error (error, "failed to add update ref %s: ", ref);
-               gs_flatpak_error_convert (error);
-               return FALSE;
+
+       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)) {
+                       g_prefix_error (error, "failed to add update ref %s: ", ref);
+                       gs_flatpak_error_convert (error);
+                       return FALSE;
+               }
        }
+
        if (!flatpak_transaction_run (transaction, cancellable, error)) {
-               g_prefix_error (error, "failed to run transaction for %s: ", ref);
                gs_flatpak_error_convert (error);
                return FALSE;
        }
@@ -716,12 +727,18 @@ gs_plugin_update_app (GsPlugin *plugin,
                gs_flatpak_error_convert (error);
                return FALSE;
        }
-       if (!gs_flatpak_refine_app (flatpak, app,
-                                   GS_PLUGIN_REFINE_FLAGS_REQUIRE_RUNTIME,
-                                   cancellable, error)) {
-               g_prefix_error (error, "failed to run refine for %s: ", ref);
-               gs_flatpak_error_convert (error);
-               return FALSE;
+       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 (!gs_flatpak_refine_app (flatpak, app,
+                                           GS_PLUGIN_REFINE_FLAGS_REQUIRE_RUNTIME,
+                                           cancellable, error)) {
+                       g_prefix_error (error, "failed to run refine for %s: ", ref);
+                       gs_flatpak_error_convert (error);
+                       return FALSE;
+               }
        }
        return TRUE;
 }


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