[gnome-builder] flatpak: transfer cancellable instead of force_exit



commit 59c8b70c5fe25cc43975aa531fa879f83ee3a535
Author: Christian Hergert <chergert redhat com>
Date:   Tue May 4 20:35:59 2021 -0700

    flatpak: transfer cancellable instead of force_exit
    
    This is *slightly* better in that we can give the transaction the
    ability to cancel itself.

 src/plugins/flatpak/daemon/ipc-flatpak-service-impl.c | 11 ++++++++++-
 .../daemon/org.gnome.Builder.Flatpak.Transfer.xml     |  1 +
 src/plugins/flatpak/gbp-flatpak-runtime-provider.c    | 19 +++++--------------
 3 files changed, 16 insertions(+), 15 deletions(-)
---
diff --git a/src/plugins/flatpak/daemon/ipc-flatpak-service-impl.c 
b/src/plugins/flatpak/daemon/ipc-flatpak-service-impl.c
index 71edbc682..b88763599 100644
--- a/src/plugins/flatpak/daemon/ipc-flatpak-service-impl.c
+++ b/src/plugins/flatpak/daemon/ipc-flatpak-service-impl.c
@@ -626,6 +626,7 @@ typedef struct
   IpcFlatpakTransfer    *transfer;
   char                  *parent_window;
   GArray                *refs;
+  GCancellable          *cancellable;
 } InstallState;
 
 static void
@@ -634,6 +635,7 @@ install_state_free (InstallState *state)
   g_clear_object (&state->installation);
   g_clear_object (&state->invocation);
   g_clear_object (&state->transfer);
+  g_clear_object (&state->cancellable);
   g_clear_pointer (&state->refs, g_array_unref);
   g_clear_pointer (&state->parent_window, g_free);
   g_slice_free (InstallState, state);
@@ -883,13 +885,20 @@ ipc_flatpak_service_impl_install (IpcFlatpakService     *service,
     }
 
   state = g_slice_new0 (InstallState);
+  state->cancellable = g_cancellable_new ();
   state->installation = ipc_flatpak_service_impl_ref_user_installation (self);
   state->invocation = g_steal_pointer (&invocation);
   state->refs = g_array_ref (refs);
   state->parent_window = parent_window[0] ? g_strdup (parent_window) : NULL;
   state->transfer = g_object_ref (transfer);
 
-  task = g_task_new (self, NULL, NULL, NULL);
+  g_signal_connect_object (transfer,
+                           "cancel",
+                           G_CALLBACK (g_cancellable_cancel),
+                           state->cancellable,
+                           G_CONNECT_SWAPPED);
+
+  task = g_task_new (self, state->cancellable, NULL, NULL);
   g_task_set_source_tag (task, ipc_flatpak_service_impl_install);
   g_task_set_task_data (task, state, (GDestroyNotify)install_state_free);
   g_task_run_in_thread (task, install_worker);
diff --git a/src/plugins/flatpak/daemon/org.gnome.Builder.Flatpak.Transfer.xml 
b/src/plugins/flatpak/daemon/org.gnome.Builder.Flatpak.Transfer.xml
index fc12a5259..7f2452807 100644
--- a/src/plugins/flatpak/daemon/org.gnome.Builder.Flatpak.Transfer.xml
+++ b/src/plugins/flatpak/daemon/org.gnome.Builder.Flatpak.Transfer.xml
@@ -23,6 +23,7 @@
   <interface name="org.gnome.Builder.Flatpak.Transfer">
     <property name="Fraction" type="d" access="readwrite"/>
     <property name="Message" type="s" access="readwrite"/>
+    <signal name="Cancel"/>
     <method name="Confirm">
       <arg name="refs" type="as" direction="in"/>
     </method>
diff --git a/src/plugins/flatpak/gbp-flatpak-runtime-provider.c 
b/src/plugins/flatpak/gbp-flatpak-runtime-provider.c
index 8c40eabff..424fbb2b9 100644
--- a/src/plugins/flatpak/gbp-flatpak-runtime-provider.c
+++ b/src/plugins/flatpak/gbp-flatpak-runtime-provider.c
@@ -423,6 +423,11 @@ gbp_flatpak_runtime_provider_bootstrap (IdeTask      *task,
                                G_CONNECT_SWAPPED);
 
       transfer = ipc_flatpak_transfer_impl_new (context);
+      g_signal_connect_object (ide_task_get_cancellable (task),
+                               "cancelled",
+                               G_CALLBACK (ipc_flatpak_transfer_emit_cancel),
+                               state->transfer,
+                               G_CONNECT_SWAPPED);
       g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (transfer),
                                         g_dbus_proxy_get_connection (G_DBUS_PROXY (service)),
                                         transfer_path,
@@ -472,8 +477,6 @@ gbp_flatpak_runtime_provider_bootstrap_async (IdeRuntimeProvider  *provider,
   g_autoptr(IdeTask) task = NULL;
   g_autofree char *full_sdk = NULL;
   g_autofree char *full_platform = NULL;
-  GbpFlatpakClient *client;
-  IdeContext *context;
   const char *arch;
   Bootstrap *state;
   IdeConfig *config;
@@ -486,8 +489,6 @@ gbp_flatpak_runtime_provider_bootstrap_async (IdeRuntimeProvider  *provider,
 
   arch = ide_pipeline_get_arch (pipeline);
   config = ide_pipeline_get_config (pipeline);
-  context = ide_object_get_context (IDE_OBJECT (pipeline));
-  client = gbp_flatpak_client_from_context (context);
 
   state = g_slice_new0 (Bootstrap);
   state->runtime_id = g_strdup (ide_config_get_runtime_id (config));
@@ -499,16 +500,6 @@ gbp_flatpak_runtime_provider_bootstrap_async (IdeRuntimeProvider  *provider,
   ide_task_set_return_on_cancel (task, FALSE);
   ide_task_set_release_on_propagate (task, FALSE);
 
-  /* If a task is cancelled, we need to force-quit the client process or else
-   * it will happily keep installing runtimes for us. This should, for the
-   * most part, really test the correctness of Flatpak transactions!
-   */
-  g_signal_connect_object (ide_task_get_cancellable (task),
-                           "cancelled",
-                           G_CALLBACK (gbp_flatpak_client_force_exit),
-                           client,
-                           G_CONNECT_SWAPPED);
-
   /* Collect all of the runtimes that could be needed */
   if (GBP_IS_FLATPAK_MANIFEST (config))
     {


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