[gnome-software/wip/kalev/flatpak-fixes: 1/2] flatpak: On error, restore the state for all apps in a transaction



commit b4c7f47d916effd52322835709b6ebe1b8ec080f
Author: Kalev Lember <klember redhat com>
Date:   Wed Oct 3 13:53:34 2018 +0200

    flatpak: On error, restore the state for all apps in a transaction
    
    Even though the error we get is for one app, it causes the whole
    transaction to fail. Restore the state for all the apps involved in the
    transaction so that they wouldn't get forever stuck in INSTALLING state.
    
    https://gitlab.gnome.org/GNOME/gnome-software/issues/483

 plugins/flatpak/gs-flatpak-transaction.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)
---
diff --git a/plugins/flatpak/gs-flatpak-transaction.c b/plugins/flatpak/gs-flatpak-transaction.c
index b788f25d..c10306b4 100644
--- a/plugins/flatpak/gs-flatpak-transaction.c
+++ b/plugins/flatpak/gs-flatpak-transaction.c
@@ -1,6 +1,7 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  *
  * Copyright (C) 2018 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2018 Kalev Lember <klember redhat com>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -242,17 +243,31 @@ _transaction_operation_done (FlatpakTransaction *transaction,
        }
 }
 
-
 static gboolean
 _transaction_operation_error (FlatpakTransaction *transaction,
                              FlatpakTransactionOperation *operation,
                              const GError *error,
                              FlatpakTransactionErrorDetails detail)
 {
-       /* invalidate */
-       GsApp *app = _transaction_operation_get_app (operation);
-       if (app != NULL)
+       GsFlatpakTransaction *self = GS_FLATPAK_TRANSACTION (transaction);
+       g_autolist(GObject) ops = NULL;
+
+       /* whole transaction failed; restore the state for all the apps */
+       ops = flatpak_transaction_get_operations (transaction);
+       for (GList *l = ops; l != NULL; l = l->next) {
+               FlatpakTransactionOperation *op = l->data;
+               const gchar *ref = flatpak_transaction_operation_get_ref (op);
+               g_autoptr(GsApp) app = _ref_to_app (self, ref);
+
+               if (app == NULL) {
+                       g_warning ("failed to find app for %s",
+                                  flatpak_transaction_operation_get_ref (operation));
+                       continue;
+               }
+
                gs_app_set_state_recover (app);
+       }
+
        if (g_error_matches (error, FLATPAK_ERROR, FLATPAK_ERROR_SKIPPED)) {
                g_printerr ("%s", error->message);
                return TRUE;


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