From fd00d9e11d9e49f9df9aaceb7ce2ae2c20ea3da8 Mon Sep 17 00:00:00 2001 From: Umang Jain Date: Wed, 21 Nov 2018 18:19:35 +0530 Subject: [PATCH] system-helper: Add CancelPull D-Bus method If there is a pull failure in a child repo created by GetChildRepoForPull system helper method, there is no way to go back to the system helper and notify it to cleanup. Therefore, CancelPull is required on the pull failure error path, so that the ongoing pull can be cleaned up nicely and prevent any dangling mounts and subprocesses. https://github.com/ostreedev/ostree/issues/1723 --- data/org.freedesktop.Flatpak.xml | 7 +++++ system-helper/flatpak-system-helper.c | 40 ++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/data/org.freedesktop.Flatpak.xml b/data/org.freedesktop.Flatpak.xml index 8e3b48ed59..435f1e1e63 100644 --- a/data/org.freedesktop.Flatpak.xml +++ b/data/org.freedesktop.Flatpak.xml @@ -167,6 +167,13 @@ + + + + + + diff --git a/system-helper/flatpak-system-helper.c b/system-helper/flatpak-system-helper.c index 66aa36820b..bd2312da58 100644 --- a/system-helper/flatpak-system-helper.c +++ b/system-helper/flatpak-system-helper.c @@ -1812,6 +1812,42 @@ handle_update_summary (FlatpakSystemHelper *object, return TRUE; } +static gboolean +handle_cancel_pull (FlatpakSystemHelper *object, + GDBusMethodInvocation *invocation, + const gchar *arg_installation, + const gchar *arg_repo_path) +{ + g_autoptr(OngoingPull) ongoing_pull = NULL; + g_autoptr(FlatpakDir) system = NULL; + g_autoptr(GError) error = NULL; + + g_debug ("CancelPull %s", arg_installation); + + system = dir_get_system (arg_installation, &error); + if (system == NULL) + { + g_dbus_method_invocation_return_gerror (invocation, error); + return TRUE; + } + + ongoing_pull = take_ongoing_pull_by_dir (arg_repo_path); + if (ongoing_pull != NULL) + { + ongoing_pull_teardown (ongoing_pull); + ongoing_pull_unref (ongoing_pull); + } + else + { + /* Should not be reached */ + g_warning ("Cannot find ongoing pull to cancel at: %s", arg_repo_path); + } + + flatpak_system_helper_complete_cancel_pull (object, invocation); + + return TRUE; +} + static gboolean flatpak_authorize_method_handler (GDBusInterfaceSkeleton *interface, GDBusMethodInvocation *invocation, @@ -1941,7 +1977,8 @@ flatpak_authorize_method_handler (GDBusInterfaceSkeleton *interface, g_strcmp0 (method_name, "EnsureRepo") == 0 || g_strcmp0 (method_name, "RunTriggers") == 0 || g_strcmp0 (method_name, "UpdateSummary") == 0 || - g_strcmp0 (method_name, "GetChildRepoForPull") == 0) + g_strcmp0 (method_name, "GetChildRepoForPull") == 0 || + g_strcmp0 (method_name, "CancelPull") == 0) { const char *remote; @@ -2013,6 +2050,7 @@ on_bus_acquired (GDBusConnection *connection, g_signal_connect (helper, "handle-run-triggers", G_CALLBACK (handle_run_triggers), NULL); g_signal_connect (helper, "handle-update-summary", G_CALLBACK (handle_update_summary), NULL); g_signal_connect (helper, "handle-get-child-repo-for-pull", G_CALLBACK (handle_get_child_repo_for_pull), NULL); + g_signal_connect (helper, "handle-cancel-pull", G_CALLBACK (handle_cancel_pull), NULL); g_signal_connect (helper, "g-authorize-method", G_CALLBACK (flatpak_authorize_method_handler),