<div dir="ltr"><div class="gmail_default"><font face="verdana, sans-serif"><font color="#000000">After dra</font><font color="#000000">gging a zero-size file, then I open it in guest, </font></font></div><div class="gmail_default">
<font face="verdana, sans-serif"><font color="#000000">I get a warning message box which says:</font></font></div>
<div class="gmail_default">
<font color="#000000" face="verdana, sans-serif">"the process cannot access the file because it is being used by another process".</font></div><div class="gmail_default"><font face="verdana, sans-serif"><font color="#000000">And I </font><span style="color:rgb(0,0,0)">get to know the file is occupied by</span><span style="color:rgb(0,0,0)"> vdagent. Now we </span></font><span style="color:rgb(0,0,0);font-family:'Microsoft YaHei';font-size:12.800000190734863px;white-space:nowrap">look back the </span><span style="color:rgb(0,0,0);font-family:'Microsoft YaHei';font-size:12.800000190734863px;white-space:nowrap">process:</span></div>
<div class="gmail_default"><span style="color:rgb(0,0,0);font-family:'Microsoft YaHei';font-size:12.800000190734863px;white-space:nowrap"><br></span></div><div class="gmail_default"><font color="#000000" face="Microsoft YaHei"><span style="white-space:nowrap">a) When dragging a zero-size file, spice-gtk gets the name and size, then sends</span></font></div>
<div class="gmail_default"><font color="#000000" face="Microsoft YaHei"><span style="white-space:nowrap">the message to vd_agent with VD_AGENT_FILE_XFER_START</span></font></div><div class="gmail_default"><span style="color:rgb(0,0,0);font-family:'Microsoft YaHei';white-space:nowrap">b) vd_agent receives and parsers the message, then gets file name and size, creates(open) </span></div>
<div class="gmail_default"><span style="color:rgb(0,0,0);font-family:'Microsoft YaHei';white-space:nowrap">the </span><span style="color:rgb(0,0,0);font-family:'Microsoft YaHei';white-space:nowrap">file and </span><span style="color:rgb(0,0,0);font-family:'Microsoft YaHei';white-space:nowrap">gets the handler, at last, sends </span><font color="#000000" face="Microsoft YaHei"><span style="white-space:nowrap">VD_AGENT_FILE_XFER_STATUS_CAN_SEND_DATA</span></font></div>
<div class="gmail_default"><span style="color:rgb(0,0,0);font-family:'Microsoft YaHei';white-space:nowrap">c) spice-gtk receives the </span><font color="#000000" face="Microsoft YaHei"><span style="white-space:nowrap">VD_AGENT_FILE_XFER_STATUS_CAN_SEND_DATA message, </span></font></div>
<div class="gmail_default"><font color="#000000" face="Microsoft YaHei"><span style="white-space:nowrap">the sends </span></font><span style="white-space:nowrap;color:rgb(0,0,0);font-family:'Microsoft YaHei'">data with VD_AGENT_FILE_XFER_DATA</span></div>
<div class="gmail_default"><font color="#000000" face="Microsoft YaHei"><span style="white-space:nowrap">d) vd_agent receives and writes data to the file opened</span></font></div><div class="gmail_default"><font color="#000000" face="Microsoft YaHei"><span style="white-space:nowrap">e) After finishing the writing, vd_agent closes the handler</span></font></div>
<div class="gmail_default"><font color="#000000" face="Microsoft YaHei"><span style="white-space:nowrap"><br></span></font></div><div class="gmail_default"><font color="#000000" face="Microsoft YaHei"><span style="white-space:nowrap">But in step c, we take a look the code:</span></font></div>
<div class="gmail_default"><font color="#000000" face="Microsoft YaHei"><span style="white-space:nowrap">//spice-channel.c</span></font></div><div class="gmail_default"><font color="#000000" face="Microsoft YaHei"><span style="white-space:nowrap"><div class="gmail_default" style>
>static void file_xfer_read_cb(...)</div><div class="gmail_default" style>>{</div><div class="gmail_default" style>> //...</div><div class="gmail_default" style>> count = g_input_stream_read_finish(G_INPUT_STREAM(task->file_stream), res, &error);</div>
<div class="gmail_default" style>> if (count > 0) {</div><div class="gmail_default" style>> task->read_bytes += count;</div><div class="gmail_default" style>> file_xfer_queue(task, count);</div>
<div class="gmail_default" style>> file_xfer_flush_async(channel, task->cancellable,</div><div class="gmail_default" style>> file_xfer_data_flushed_cb, task);</div><div class="gmail_default" style>
> task->pending = TRUE;</div><div class="gmail_default" style>> } else if (error) {</div><div class="gmail_default" style>> VDAgentFileXferStatusMessage msg = {</div><div class="gmail_default" style>
> .id = task->id,</div><div class="gmail_default" style>> .result = VD_AGENT_FILE_XFER_STATUS_ERROR,</div><div class="gmail_default" style>> };</div><div class="gmail_default" style>
> agent_msg_queue_many(task->channel, VD_AGENT_FILE_XFER_STATUS,</div><div class="gmail_default" style>> &msg, sizeof(msg), NULL);</div><div class="gmail_default" style>> spice_channel_wakeup(SPICE_CHANNEL(task->channel), FALSE);</div>
<div class="gmail_default" style>> file_xfer_completed(task, error);</div><div class="gmail_default" style>> }</div><div class="gmail_default" style>>}</div><div class="gmail_default" style><br></div><div class="gmail_default" style>
If count == 0, then it does nothing! </div><div class="gmail_default" style>Then vd_agent will receive nothing after opening a file, and always occupy the file.</div><div class="gmail_default" style>Here we close the file if file_size = 0, even though it <span style="font-size:12.800000190734863px">doesn't make sense to send </span></div>
<div class="gmail_default" style><span style="font-size:12.800000190734863px">a zero-size file.</span></div></span></font><font color="#000000" face="Microsoft YaHei"><span style="white-space:nowrap"><div class="gmail_default" style>
<br></div></span></font></div><div class="gmail_default"><dt style="color:rgb(69,69,69);font-family:'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif;font-size:14px"><div class="gmail_default" style="font-size:small;font-family:verdana,sans-serif;color:rgb(0,0,0);display:inline">
</div><span style="color:rgb(34,34,34);font-family:arial;font-size:small">---</span><br style="color:rgb(34,34,34);font-family:arial;font-size:small"><span style="color:rgb(34,34,34);font-family:arial;font-size:small"> vdagent/file_xfer.cpp | 4 ++++</span><br style="color:rgb(34,34,34);font-family:arial;font-size:small">
<span style="color:rgb(34,34,34);font-family:arial;font-size:small"> 1 file changed, 4 insertions(+)</span><br style="color:rgb(34,34,34);font-family:arial;font-size:small"><br style="color:rgb(34,34,34);font-family:arial;font-size:small">
<span style="color:rgb(34,34,34);font-family:arial;font-size:small">diff --git a/vdagent/file_xfer.cpp b/vdagent/file_xfer.cpp</span><br style="color:rgb(34,34,34);font-family:arial;font-size:small"><span style="color:rgb(34,34,34);font-family:arial;font-size:small">index 34a9ee6..17d842e 100644</span><br style="color:rgb(34,34,34);font-family:arial;font-size:small">
<span style="color:rgb(34,34,34);font-family:arial;font-size:small">--- a/vdagent/file_xfer.cpp</span><br style="color:rgb(34,34,34);font-family:arial;font-size:small"><span style="color:rgb(34,34,34);font-family:arial;font-size:small">+++ b/vdagent/file_xfer.cpp</span><br style="color:rgb(34,34,34);font-family:arial;font-size:small">
<span style="color:rgb(34,34,34);font-family:arial;font-size:small">@@ -89,6 +89,10 @@ void FileXfer::handle_start(</span><span style="color:rgb(34,34,34);font-family:arial;font-size:small">VDAgentFileXferStartMessage* start,</span><br style="color:rgb(34,34,34);font-family:arial;font-size:small">
<span style="color:rgb(34,34,34);font-family:arial;font-size:small"> vd_printf("failed creating %s %lu", file_path, GetLastError());</span><br style="color:rgb(34,34,34);font-family:arial;font-size:small">
<span style="color:rgb(34,34,34);font-family:arial;font-size:small"> return;</span><br style="color:rgb(34,34,34);font-family:arial;font-size:small"><span style="color:rgb(34,34,34);font-family:arial;font-size:small"> }</span><br style="color:rgb(34,34,34);font-family:arial;font-size:small">
<span style="color:rgb(34,34,34);font-family:arial;font-size:small">+ if (file_size == 0){</span><br style="color:rgb(34,34,34);font-family:arial;font-size:small"><span style="color:rgb(34,34,34);font-family:arial;font-size:small">+ CloseHandle(handle);</span><br style="color:rgb(34,34,34);font-family:arial;font-size:small">
<span style="color:rgb(34,34,34);font-family:arial;font-size:small">+ return;</span><br style="color:rgb(34,34,34);font-family:arial;font-size:small"><span style="color:rgb(34,34,34);font-family:arial;font-size:small">+ }</span><br style="color:rgb(34,34,34);font-family:arial;font-size:small">
<span style="color:rgb(34,34,34);font-family:arial;font-size:small"> task = new FileXferTask(handle, file_size, file_path);</span><br style="color:rgb(34,34,34);font-family:arial;font-size:small"><span style="color:rgb(34,34,34);font-family:arial;font-size:small"> _tasks[start->id] = task;</span><br style="color:rgb(34,34,34);font-family:arial;font-size:small">
<span style="color:rgb(34,34,34);font-family:arial;font-size:small"> status->result = VD_AGENT_FILE_XFER_STATUS_CAN_</span><span style="color:rgb(34,34,34);font-family:arial;font-size:small">SEND_DATA;</span><br style="color:rgb(34,34,34);font-family:arial;font-size:small">
<span style="color:rgb(34,34,34);font-family:arial;font-size:small"><font color="#888888">--<br>1.9.3</font></span><span style="line-height:1.429em"><br></span></dt><dt style="color:rgb(69,69,69);font-family:'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif;font-size:14px">
<br></dt></div>
<div class="gmail_default">-- </div><div dir="ltr"><font color="#cfe2f3">Q</font><font color="#9fc5e8">S</font><font color="#6fa8dc">B</font><font color="#3d85c6">D</font><font color="#0b5394">T</font><font color="#073763">0</font><font color="#0c343d">R</font><font color="#134f5c">F</font><font color="#45818e">U</font><font color="#76a5af">i</font><font color="#a2c4c9">B</font><font color="#d0e0e3">G</font><font color="#d9ead3">U</font><font color="#b6d7a8">k</font><font color="#93c47d">9</font><font color="#6aa84f">N</font><font color="#38761d">I</font><font color="#274e13">F</font><font color="#7f6000">J</font><font color="#bf9000">J</font><font color="#f1c232">R</font><font color="#ffd966">V</font><font color="#ffe599">N</font><font color="#fff2cc">U</font><font color="#fce5cd">I</font><font color="#f9cb9c">E</font><font color="#f6b26b">9</font><font color="#e69138">G</font><font color="#b45f06">I</font><font color="#783f04">E</font><font color="#660000">N</font><font color="#990000">U</font><font color="#cc0000">U</font><font color="#e06666">0V</font><font color="#ea9999">V</font></div>
</div>