[Spice-devel] [PATCH spice-gtk] Ensure that file transfers get cancelled

Jonathon Jongsma jjongsma at redhat.com
Thu Apr 7 20:51:16 UTC 2016


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().
---
 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 4a1f58a..85353d4 100644
--- a/src/channel-main.c
+++ b/src/channel-main.c
@@ -1912,13 +1912,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);
     }
@@ -2944,6 +2937,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.4.11



More information about the Spice-devel mailing list