[gnome-software/wip/kalev/more-flatpak-fixes: 1/3] flatpak: Propagate operation error



commit 96dcb8eeae29cd597582a6bae83848561b735fcf
Author: Kalev Lember <klember redhat com>
Date:   Thu Oct 4 07:40:12 2018 +0200

    flatpak: Propagate operation error
    
    When one of the individual ops fails, operation_error() vfunc returns
    the actual error that happened, and flatpak_transaction_run() returns
    just a generic FLATPAK_ERROR_ABORTED.
    
    This commit adds new gs_flatpak_transaction_run() that wraps
    flatpak_transaction_run() so that we can propagate the errors that we
    get in the operation_error() vfunc.

 plugins/flatpak/gs-flatpak-transaction.c | 33 ++++++++++++++++++++++++++++++--
 plugins/flatpak/gs-flatpak-transaction.h |  3 +++
 plugins/flatpak/gs-plugin-flatpak.c      |  8 ++++----
 3 files changed, 38 insertions(+), 6 deletions(-)
---
diff --git a/plugins/flatpak/gs-flatpak-transaction.c b/plugins/flatpak/gs-flatpak-transaction.c
index ec3dca52..9be98d1a 100644
--- a/plugins/flatpak/gs-flatpak-transaction.c
+++ b/plugins/flatpak/gs-flatpak-transaction.c
@@ -29,6 +29,7 @@ struct _GsFlatpakTransaction {
        FlatpakTransaction       parent_instance;
        FlatpakInstallation     *installation;
        GHashTable              *refhash;       /* ref:GsApp */
+       GError                  *first_operation_error;
 };
 
 enum {
@@ -56,6 +57,8 @@ gs_flatpak_transaction_finalize (GObject *object)
 
        g_assert (self != NULL);
        g_hash_table_unref (self->refhash);
+       if (self->first_operation_error)
+               g_error_free (self->first_operation_error);
 
        G_OBJECT_CLASS (gs_flatpak_transaction_parent_class)->finalize (object);
 }
@@ -106,6 +109,28 @@ _transaction_operation_get_app (FlatpakTransactionOperation *op)
        return g_object_get_data (G_OBJECT (op), "GsApp");
 }
 
+gboolean
+gs_flatpak_transaction_run (FlatpakTransaction *transaction,
+                            GCancellable *cancellable,
+                            GError **error)
+
+{
+       GsFlatpakTransaction *self = GS_FLATPAK_TRANSACTION (transaction);
+       g_autoptr(GError) local_error = NULL;
+
+       if (!flatpak_transaction_run (transaction, cancellable, &local_error)) {
+               if (self->first_operation_error != NULL) {
+                       g_propagate_error (error, g_steal_pointer (&self->first_operation_error));
+                       return FALSE;
+               } else {
+                       g_propagate_error (error, g_steal_pointer (&local_error));
+                       return FALSE;
+               }
+       }
+
+       return TRUE;
+}
+
 static gboolean
 _transaction_ready (FlatpakTransaction *transaction)
 {
@@ -269,9 +294,13 @@ _transaction_operation_error (FlatpakTransaction *transaction,
        }
 
        if (g_error_matches (error, FLATPAK_ERROR, FLATPAK_ERROR_SKIPPED)) {
-               return TRUE;
+               return TRUE; /* continue */
        }
-       return FALSE;
+
+       if (self->first_operation_error == NULL)
+               g_propagate_error (&self->first_operation_error,
+                                  g_error_copy (error));
+       return FALSE; /* stop */
 }
 
 static int
diff --git a/plugins/flatpak/gs-flatpak-transaction.h b/plugins/flatpak/gs-flatpak-transaction.h
index 56b6a676..faf71807 100644
--- a/plugins/flatpak/gs-flatpak-transaction.h
+++ b/plugins/flatpak/gs-flatpak-transaction.h
@@ -39,6 +39,9 @@ GsApp                 *gs_flatpak_transaction_get_app_by_ref  (FlatpakTransaction     
*transaction,
                                                                 const gchar            *ref);
 void                    gs_flatpak_transaction_add_app         (FlatpakTransaction     *transaction,
                                                                 GsApp                  *app);
+gboolean                gs_flatpak_transaction_run             (FlatpakTransaction     *transaction,
+                                                                GCancellable           *cancellable,
+                                                                GError                 **error);
 
 G_END_DECLS
 
diff --git a/plugins/flatpak/gs-plugin-flatpak.c b/plugins/flatpak/gs-plugin-flatpak.c
index dc29e9c9..37f104e8 100644
--- a/plugins/flatpak/gs-plugin-flatpak.c
+++ b/plugins/flatpak/gs-plugin-flatpak.c
@@ -480,7 +480,7 @@ gs_plugin_download (GsPlugin *plugin, GsAppList *list,
                        return FALSE;
                }
        }
-       if (!flatpak_transaction_run (transaction, cancellable, error)) {
+       if (!gs_flatpak_transaction_run (transaction, cancellable, error)) {
                gs_flatpak_error_convert (error);
                return FALSE;
        }
@@ -518,7 +518,7 @@ gs_plugin_app_remove (GsPlugin *plugin,
                gs_flatpak_error_convert (error);
                return FALSE;
        }
-       if (!flatpak_transaction_run (transaction, cancellable, error)) {
+       if (!gs_flatpak_transaction_run (transaction, cancellable, error)) {
                g_prefix_error (error, "failed to run transaction for %s: ", ref);
                gs_flatpak_error_convert (error);
                return FALSE;
@@ -654,7 +654,7 @@ gs_plugin_app_install (GsPlugin *plugin,
        }
 
        /* run transaction */
-       if (!flatpak_transaction_run (transaction, cancellable, error)) {
+       if (!gs_flatpak_transaction_run (transaction, cancellable, error)) {
                g_prefix_error (error, "failed to run transaction for %s: ",
                                gs_app_get_unique_id (app));
                gs_flatpak_error_convert (error);
@@ -716,7 +716,7 @@ gs_plugin_update (GsPlugin *plugin,
                }
        }
 
-       if (!flatpak_transaction_run (transaction, cancellable, error)) {
+       if (!gs_flatpak_transaction_run (transaction, cancellable, error)) {
                gs_flatpak_error_convert (error);
                return FALSE;
        }


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