Blob Blame History Raw
From 8f74b35fa15fa08054e6f14612219f3818224f7b Mon Sep 17 00:00:00 2001
From: Jonathon Jongsma <jjongsma@redhat.com>
Date: Thu, 7 Apr 2016 15:42:14 -0500
Subject: [PATCH 4/5] Ensure that file transfers get cancelled

When canceling a file transfer task in spicy, the client would often
stop sending additional data, but it would not send a "CANCELLED"
message to the guest. Because of this, the partial file would remain in
the guest's downloads folder until the spice client disconnected, at
which point the vdagent would remove the unfinshed file.

This CANCELLED status message was only being sent if the task was
canceled during the async file read operation. If you cancel a task,
it's quite likely that it will happen during other operations
(e.g. file_xfer_flush_async(), etc). In order to handle these scenarios
(and make sure that the file gets canceled properly), send the
FILE_XFER_STATUS message in spice_file_transfer_task_completed().

(cherry picked from commit 4da4d9201cc3f86e38f00388cdd6157fe70e3328)
---
 src/channel-main.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/channel-main.c b/src/channel-main.c
index e5a70af..67fce5b 100644
--- a/src/channel-main.c
+++ b/src/channel-main.c
@@ -1919,13 +1919,6 @@ static void file_xfer_read_cb(GObject *source_object,
                               file_xfer_data_flushed_cb, self);
         self->priv->pending = TRUE;
     } else if (error) {
-        VDAgentFileXferStatusMessage msg = {
-            .id = self->priv->id,
-            .result = error->code == G_IO_ERROR_CANCELLED ?
-                    VD_AGENT_FILE_XFER_STATUS_CANCELLED : VD_AGENT_FILE_XFER_STATUS_ERROR,
-        };
-        agent_msg_queue_many(self->priv->channel, VD_AGENT_FILE_XFER_STATUS,
-                             &msg, sizeof(msg), NULL);
         spice_channel_wakeup(SPICE_CHANNEL(self->priv->channel), FALSE);
         spice_file_transfer_task_completed(self, error);
     }
@@ -2946,6 +2939,16 @@ static void spice_file_transfer_task_completed(SpiceFileTransferTask *self,
         self->priv->error = error;
     }
 
+    if (self->priv->error) {
+        VDAgentFileXferStatusMessage msg = {
+            .id = self->priv->id,
+            .result = error->code == G_IO_ERROR_CANCELLED ?
+                    VD_AGENT_FILE_XFER_STATUS_CANCELLED : VD_AGENT_FILE_XFER_STATUS_ERROR,
+        };
+        agent_msg_queue_many(self->priv->channel, VD_AGENT_FILE_XFER_STATUS,
+                             &msg, sizeof(msg), NULL);
+    }
+
     if (self->priv->pending)
         return;
 
-- 
2.8.1