Skip to content

Commit

Permalink
system-helper: Add CancelPull D-Bus method
Browse files Browse the repository at this point in the history
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.

ostreedev/ostree#1723
  • Loading branch information
Umang Jain committed Nov 28, 2018
1 parent c0896af commit fd00d9e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
7 changes: 7 additions & 0 deletions data/org.freedesktop.Flatpak.xml
Expand Up @@ -167,6 +167,13 @@
<arg type='s' name='repo_path' direction='out'/>
</method>

<!-- This method cancels an ongoing pull at repo_path. The cancellation triggered
by the client helps to cleanup the mount setup -->
<method name="CancelPull">
<arg type='s' name='installation' direction='in'/>
<arg type='s' name='repo_path' direction='in'/>
</method>

</interface>

</node>
40 changes: 39 additions & 1 deletion system-helper/flatpak-system-helper.c
Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit fd00d9e

Please sign in to comment.