[gnome-software/gnome-3-30] flatpak: Propagate operation error



commit ae11e070e9524b64a84b45f573309197caa64bf0
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 | 34 ++++++++++++++++++++++++++++++--
 plugins/flatpak/gs-flatpak-transaction.h |  3 +++
 plugins/flatpak/gs-plugin-flatpak.c      |  8 ++++----
 3 files changed, 39 insertions(+), 6 deletions(-)
---
diff --git a/plugins/flatpak/gs-flatpak-transaction.c b/plugins/flatpak/gs-flatpak-transaction.c
index ec3dca52..e296fc87 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 != NULL)
+               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) error_local = NULL;
+
+       if (!flatpak_transaction_run (transaction, cancellable, &error_local)) {
+               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 (&error_local));
+                       return FALSE;
+               }
+       }
+
+       return TRUE;
+}
+
 static gboolean
 _transaction_ready (FlatpakTransaction *transaction)
 {
@@ -269,9 +294,14 @@ _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 202ca282..e303889d 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]