[gnome-software] flatpak: Construct one big transaction for all updates



commit 26a3228a825a33e9de53989428914ce635b0ab59
Author: Kalev Lember <klember redhat com>
Date:   Thu Nov 15 01:27:14 2018 +0100

    flatpak: Construct one big transaction for all updates
    
    Let's give this another try. The reason we reverted this the first time
    was that it regressed error reporting: as the plugin loader no longer
    drives app updating, it didn't know how to map errors that occur to apps
    and then we got errors such as 'Unable to update "(null)"' in the UI.
    However, this time around we have a mechanism for passing app IDs from
    the plugins up to the plugin loader and this commit is updated to make
    use of that.
    
    ---
    
    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.
    
    This reverts commit eee60ee8905b73bb874a4900a261ad1b54f958d8.

 plugins/flatpak/gs-flatpak-transaction.c |  3 ++
 plugins/flatpak/gs-plugin-flatpak.c      | 62 +++++++++++++++++++++-----------
 2 files changed, 45 insertions(+), 20 deletions(-)
---
diff --git a/plugins/flatpak/gs-flatpak-transaction.c b/plugins/flatpak/gs-flatpak-transaction.c
index c6735515..606187d2 100644
--- a/plugins/flatpak/gs-flatpak-transaction.c
+++ b/plugins/flatpak/gs-flatpak-transaction.c
@@ -292,6 +292,7 @@ _transaction_operation_error (FlatpakTransaction *transaction,
 {
        GsFlatpakTransaction *self = GS_FLATPAK_TRANSACTION (transaction);
        FlatpakTransactionOperationType operation_type = flatpak_transaction_operation_get_operation_type 
(operation);
+       GsApp *app = _transaction_operation_get_app (operation);
        const gchar *ref = flatpak_transaction_operation_get_ref (operation);
 
        if (g_error_matches (error, FLATPAK_ERROR, FLATPAK_ERROR_SKIPPED)) {
@@ -313,6 +314,8 @@ _transaction_operation_error (FlatpakTransaction *transaction,
        if (self->first_operation_error == NULL) {
                g_propagate_error (&self->first_operation_error,
                                   g_error_copy (error));
+               if (app != NULL)
+                       gs_utils_error_add_app_id (&self->first_operation_error, app);
        }
        return FALSE; /* stop */
 }
diff --git a/plugins/flatpak/gs-plugin-flatpak.c b/plugins/flatpak/gs-plugin-flatpak.c
index 0792e89c..5726c06a 100644
--- a/plugins/flatpak/gs-plugin-flatpak.c
+++ b/plugins/flatpak/gs-plugin-flatpak.c
@@ -688,17 +688,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;
 
@@ -708,19 +713,30 @@ 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;
+               }
        }
 
        /* run transaction */
-       gs_app_set_state (app, AS_APP_STATE_INSTALLING);
+       for (guint i = 0; i < gs_app_list_length (list_tmp); i++) {
+               GsApp *app = gs_app_list_index (list_tmp, i);
+               gs_app_set_state (app, AS_APP_STATE_INSTALLING);
+       }
        if (!gs_flatpak_transaction_run (transaction, cancellable, error)) {
-               g_prefix_error (error, "failed to run transaction for %s: ", ref);
+               for (guint i = 0; i < gs_app_list_length (list_tmp); i++) {
+                       GsApp *app = gs_app_list_index (list_tmp, i);
+                       gs_app_set_state_recover (app);
+               }
                gs_flatpak_error_convert (error);
-               gs_app_set_state_recover (app);
                return FALSE;
        }
        gs_plugin_updates_changed (plugin);
@@ -730,12 +746,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]