From 5e65aa2bffc6fc55cd03021f2fcdb64492cc42fe Mon Sep 17 00:00:00 2001 From: Ross Lagerwall Date: Sat, 5 Dec 2015 14:34:53 +0000 Subject: sftp: Fail cancelled jobs Fail jobs which have been marked as cancelled, otherwise the job remains and blocks unmounting. This can be reproduced by cancelling while copying a large file to/from a mount and then trying to unmount it. https://bugzilla.gnome.org/show_bug.cgi?id=759061 --- daemon/gvfsbackendsftp.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/daemon/gvfsbackendsftp.c b/daemon/gvfsbackendsftp.c index 79b880dd..8982de3a 100644 --- a/daemon/gvfsbackendsftp.c +++ b/daemon/gvfsbackendsftp.c @@ -5202,6 +5202,23 @@ try_set_attribute (GVfsBackend *backend, return TRUE; } +/* Return true if the job is finished or cancelled, failing it if needed. */ +static gboolean +check_finished_or_cancelled_job (GVfsJob *job) +{ + if (g_vfs_job_is_finished (job)) + return TRUE; + + if (g_vfs_job_is_cancelled (job)) + { + g_vfs_job_failed (job, G_IO_ERROR, G_IO_ERROR_CANCELLED, + _("Operation was cancelled")); + return TRUE; + } + + return FALSE; +} + /* The push sliding window mechanism is based on the one in the OpenSSH sftp * client. */ @@ -5464,7 +5481,7 @@ push_source_close_cb (GObject *source, GAsyncResult *res, gpointer user_data) g_input_stream_close_finish (handle->in, res, NULL); g_clear_object (&handle->in); - if (g_vfs_job_is_finished (handle->job) || g_vfs_job_is_cancelled (handle->job)) + if (check_finished_or_cancelled_job (handle->job)) { sftp_push_handle_free (handle); return; @@ -5491,7 +5508,7 @@ push_write_reply (GVfsBackendSftp *backend, handle->num_req--; - if (g_vfs_job_is_finished (job) || g_vfs_job_is_cancelled (job)) + if (check_finished_or_cancelled_job (job)) { sftp_push_handle_free (handle); return; @@ -5541,7 +5558,7 @@ push_read_cb (GObject *source, GAsyncResult *res, gpointer user_data) count = g_input_stream_read_finish (handle->in, res, &error); - if (g_vfs_job_is_finished (handle->job) || g_vfs_job_is_cancelled (handle->job)) + if (check_finished_or_cancelled_job (handle->job)) { g_clear_error (&error); sftp_push_handle_free (handle); @@ -6208,7 +6225,7 @@ pull_read_reply (GVfsBackendSftp *backend, handle->num_req--; - if (g_vfs_job_is_finished (job) || g_vfs_job_is_cancelled (job)) + if (check_finished_or_cancelled_job (job)) { } else if (reply_type == SSH_FXP_STATUS) @@ -6290,7 +6307,7 @@ pull_fstat_reply (GVfsBackendSftp *backend, { SftpPullHandle *handle = user_data; - if (g_vfs_job_is_finished (job) || g_vfs_job_is_cancelled (job)) + if (check_finished_or_cancelled_job (job)) { handle->size = PULL_SIZE_INVALID; sftp_pull_handle_free (handle); -- cgit v1.2.1