[gnome-builder] flatpak: allow cancellation of transfer



commit 980be9b1636f9b25d92cd5d4e5a10ebd6d8db2b2
Author: Christian Hergert <chergert redhat com>
Date:   Tue May 4 20:23:09 2021 -0700

    flatpak: allow cancellation of transfer
    
    Quite frankly, this can cause an issue where we get the repository into a
    state that needs repair, but I think it's better that we at least do what
    the user said than nothing at all. Data can be expensive on some networks.
    
    Ideally this should be addressed in libflatpak at:
    
      https://github.com/flatpak/flatpak/issues/4258

 .../flatpak/daemon/ipc-flatpak-service-impl.c      |  2 +-
 src/plugins/flatpak/gbp-flatpak-client.c           | 11 +++++++++++
 src/plugins/flatpak/gbp-flatpak-client.h           |  1 +
 src/plugins/flatpak/gbp-flatpak-runtime-provider.c | 22 ++++++++++++++++++++++
 4 files changed, 35 insertions(+), 1 deletion(-)
---
diff --git a/src/plugins/flatpak/daemon/ipc-flatpak-service-impl.c 
b/src/plugins/flatpak/daemon/ipc-flatpak-service-impl.c
index 8ef546e0c..71edbc682 100644
--- a/src/plugins/flatpak/daemon/ipc-flatpak-service-impl.c
+++ b/src/plugins/flatpak/daemon/ipc-flatpak-service-impl.c
@@ -922,7 +922,7 @@ chunk_insert (GStringChunk *strings,
 }
 
 static char *
-resolve_extension (GPtrArray   *installations,
+resolve_extension (GPtrArray  *installations,
                    const char *sdk,
                    const char *extension)
 {
diff --git a/src/plugins/flatpak/gbp-flatpak-client.c b/src/plugins/flatpak/gbp-flatpak-client.c
index fb5e155c3..42b335bb1 100644
--- a/src/plugins/flatpak/gbp-flatpak-client.c
+++ b/src/plugins/flatpak/gbp-flatpak-client.c
@@ -346,3 +346,14 @@ gbp_flatpak_client_get_service_finish (GbpFlatpakClient  *self,
 
   return ide_task_propagate_object (IDE_TASK (result), error);
 }
+
+void
+gbp_flatpak_client_force_exit (GbpFlatpakClient *self)
+{
+  IdeSubprocess *subprocess;
+
+  g_return_if_fail (GBP_IS_FLATPAK_CLIENT (self));
+
+  if ((subprocess = ide_subprocess_supervisor_get_subprocess (self->supervisor)))
+    ide_subprocess_force_exit (subprocess);
+}
diff --git a/src/plugins/flatpak/gbp-flatpak-client.h b/src/plugins/flatpak/gbp-flatpak-client.h
index f96ba0815..786df5349 100644
--- a/src/plugins/flatpak/gbp-flatpak-client.h
+++ b/src/plugins/flatpak/gbp-flatpak-client.h
@@ -41,6 +41,7 @@ void               gbp_flatpak_client_get_service_async  (GbpFlatpakClient     *
 IpcFlatpakService *gbp_flatpak_client_get_service_finish (GbpFlatpakClient     *self,
                                                           GAsyncResult         *result,
                                                           GError              **error);
+void               gbp_flatpak_client_force_exit         (GbpFlatpakClient     *self);
 
 static inline GbpFlatpakClient *
 gbp_flatpak_client_ensure (IdeContext *context)
diff --git a/src/plugins/flatpak/gbp-flatpak-runtime-provider.c 
b/src/plugins/flatpak/gbp-flatpak-runtime-provider.c
index bcb6b84f2..8c40eabff 100644
--- a/src/plugins/flatpak/gbp-flatpak-runtime-provider.c
+++ b/src/plugins/flatpak/gbp-flatpak-runtime-provider.c
@@ -303,11 +303,19 @@ gbp_flatpak_runtime_provider_bootstrap_complete (gpointer data)
 
   if (state->to_install->len > 0)
     {
+      g_autofree char *detailed_action_name = NULL;
+      g_autoptr(GIcon) icon = g_themed_icon_new ("process-stop-symbolic");
+
       g_assert (IDE_IS_NOTIFICATION (state->notif));
       g_assert (IPC_IS_FLATPAK_SERVICE (state->service));
       g_assert (IPC_IS_FLATPAK_TRANSFER (state->transfer));
 
+      /* Register an action that can be cancelled */
+      detailed_action_name = ide_application_create_cancel_action (IDE_APPLICATION_DEFAULT,
+                                                                   ide_task_get_cancellable (task));
+      ide_notification_add_button (state->notif, _("Cancel"), icon, detailed_action_name);
       ide_notification_attach (state->notif, IDE_OBJECT (self));
+
       ipc_flatpak_service_call_install (state->service,
                                         (const char * const *)state->to_install->pdata,
                                         state->transfer_path,
@@ -464,6 +472,8 @@ 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;
@@ -476,6 +486,8 @@ 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));
@@ -487,6 +499,16 @@ 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]