<div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small;color:#000000"><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Aug 11, 2014 at 7:04 PM, Christophe Fergeau <span dir="ltr"><<a href="mailto:cfergeau@redhat.com" target="_blank">cfergeau@redhat.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Sat, Aug 09, 2014 at 06:40:22PM +0800, Cody Chan wrote:<br>
> After dragging a zero-size file, then I open it in guest,<br>
> I get a warning message box which says:<br>
>  "the process cannot access the file because it is being used by another<br>
> process".<br>
> And I get to know the file is occupied by vdagent. Now we look back the<br>
> process:<br>
><br>
> a) When dragging a zero-size file, spice-gtk gets the name and size, then<br>
> sends<br>
> the message to vd_agent with VD_AGENT_FILE_XFER_START<br>
> b) vd_agent receives and parsers the message, then gets file name and size,<br>
> creates(open)<br>
> the file and gets the handler, at last, sends<br>
> VD_AGENT_FILE_XFER_STATUS_CAN_SEND_DATA<br>
> c) spice-gtk receives the VD_AGENT_FILE_XFER_STATUS_CAN_SEND_DATA message,<br>
> the sends data with VD_AGENT_FILE_XFER_DATA<br>
> d) vd_agent receives and writes data to the file opened<br>
> e) After finishing the writing, vd_agent closes the handler<br>
><br>
> But in step c, we take a look the code:<br>
> //spice-channel.c<br>
> >static void file_xfer_read_cb(...)<br>
> >{<br>
> >    //...<br>
> >    count = g_input_stream_read_finish(G_INPUT_STREAM(task->file_stream),<br>
> res, &error);<br>
> >    if (count > 0) {<br>
> >        task->read_bytes += count;<br>
> >        file_xfer_queue(task, count);<br>
> >        file_xfer_flush_async(channel, task->cancellable,<br>
> >                              file_xfer_data_flushed_cb, task);<br>
> >        task->pending = TRUE;<br>
> >    } else if (error) {<br>
> >        VDAgentFileXferStatusMessage msg = {<br>
> >            .id = task->id,<br>
> >            .result = VD_AGENT_FILE_XFER_STATUS_ERROR,<br>
> >        };<br>
> >        agent_msg_queue_many(task->channel, VD_AGENT_FILE_XFER_STATUS,<br>
> >                             &msg, sizeof(msg), NULL);<br>
> >        spice_channel_wakeup(SPICE_CHANNEL(task->channel), FALSE);<br>
> >        file_xfer_completed(task, error);<br>
> >    }<br>
> >}<br>
><br>
> If count == 0, then it does nothing!<br>
> Then vd_agent will receive nothing after opening a file, and always occupy<br>
> the file.<br>
> Here we close the file if file_size = 0, even though it doesn't make sense<br>
> to send<br>
> a zero-size file.<br>
<br>
</div></div>Ah, good catch, from a quick look it seems the linux agent does not<br>
handle this case properly either. This can be fixed in both agents, or<br>
alternatively, this can also be fixed in spice-gtk in file_xfer_read_cb<br>
by sending a dummy empty data message when the file size is 0.<br>
Fixing it in the agents is probably less convoluted.<br></blockquote><div><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small;color:rgb(0,0,0)">​As you've proposed​, I fix the bug in spice-gtk, and I'll send a new patch after testing.</div>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class=""><br>
><br>
> ​<br>
> ---<br>
>  vdagent/file_xfer.cpp | 4 ++++<br>
>  1 file changed, 4 insertions(+)<br>
><br>
> diff --git a/vdagent/file_xfer.cpp b/vdagent/file_xfer.cpp<br>
> index 34a9ee6..17d842e 100644<br>
> --- a/vdagent/file_xfer.cpp<br>
> +++ b/vdagent/file_xfer.cpp<br>
> @@ -89,6 +89,10 @@ void FileXfer::handle_start(VDAgentFileXferStartMessage*<br>
> start,<br>
>          vd_printf("failed creating %s %lu", file_path, GetLastError());<br>
>          return;<br>
>      }<br>
> +    if (file_size == 0){<br>
> +        CloseHandle(handle);<br>
> +        return;<br>
> +    }<br>
<br>
</div>The agent should probably return VD_AGENT_FILE_XFER_STATUS_SUCCESS in<br>
this case to let the client know this is over.<br>
<span class="HOEnZb"><font color="#888888"><br>
Christophe<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><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></div>