<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 27 Apr 2017, at 17:31, Pavel Grunt <<a href="mailto:pgrunt@redhat.com" class="">pgrunt@redhat.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">On Thu, 2017-04-27 at 10:25 -0500, Jonathon Jongsma wrote:</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">On Wed, 2017-04-26 at 17:50 -0400, Frediano Ziglio wrote:<br class=""><blockquote type="cite" class=""><blockquote type="cite" class=""><br class="">Previously, if the user attempted to transfer a file that had<br class="">the<br class="">same<br class="">name as a file that already exists on the guest, we would just<br class="">fail<br class="">the<br class="">transfer. This patch tries to match the behavior of the linux<br class="">vdagent<br class="">where we try to append an integer onto the name of the new file<br class="">to<br class="">make<br class="">it unique. For example, if you tried to transfer 'file.doc' to<br class="">the<br class="">guest<br class="">and that file already existed, it would try to create 'file.doc<br class="">(1)'<br class="">instead. If that also failed, it would attempt 'file.doc (2)',<br class="">etc,<br class="">up<br class="">to 63.<br class=""><br class=""></blockquote><br class="">Not really user friendly, Windows is really extension based.<br class="">Would be better to be 'file (1).doc' for 'file.doc'.<br class="">Yes, not easy to implement as adding " (xx)".<br class=""></blockquote><br class="">True, I just tried to copy the behavior of the linux vdagent (as<br class="">suggested in the bug), but perhaps we should do it a bit differently<br class="">for windows. Or maybe we should change both the linux and vdagent to<br class="">work this way...<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Probably. I checked Nautilus and Thunar (file managers in Gnome and</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Xfce) behavior when copying a same file in the same folder and they</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">are adding (xxx) before the extension suffix.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote><div class=""><br class=""></div><div class="">You can clone / adapt this code from glib:</div><div class=""><br class=""></div><div class=""><a href="https://github.com/GNOME/glib/blob/master/gio/glocalfile.c#L1727" class="">https://github.com/GNOME/glib/blob/master/gio/glocalfile.c#L1727</a></div><div class=""><br class=""></div>I personally like the “%.*s” ;-), it’s a smart way to cut the string. They generate something like foo.1.c and not foo(1).c, but I’m sure you can fix that :-)</div><div class=""><br class=""></div><div class="">Christophe</div><div class=""><br class=""><blockquote type="cite" class=""><div class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Pavel</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class=""><br class=""><blockquote type="cite" class=""><br class=""><blockquote type="cite" class="">Resolves: rhbz#1410181<br class="">---<br class=""> vdagent/file_xfer.cpp | 38 ++++++++++++++++++++++++++++++++--<br class="">----<br class=""> 1 file changed, 32 insertions(+), 6 deletions(-)<br class=""><br class="">diff --git a/vdagent/file_xfer.cpp b/vdagent/file_xfer.cpp<br class="">index f763ed3..14e2098 100644<br class="">--- a/vdagent/file_xfer.cpp<br class="">+++ b/vdagent/file_xfer.cpp<br class="">@@ -61,6 +61,7 @@ void<br class="">FileXfer::handle_start(VDAgentFileXferStartMessage*<br class="">start,<br class="">     HANDLE handle;<br class="">     AsUser as_user;<br class="">     int wlen;<br class="">+    int attempt = 0;<br class=""> <br class="">     status->id = start->id;<br class="">     status->result = VD_AGENT_FILE_XFER_STATUS_ERROR;<br class="">@@ -99,15 +100,40 @@ void<br class="">FileXfer::handle_start(VDAgentFileXferStartMessage*<br class="">start,<br class=""> <br class="">     file_path[wlen++] = TEXT('\\');<br class="">     file_path[wlen] = TEXT('\0');<br class="">-    if((wlen = MultiByteToWideChar(CP_UTF8, 0, file_name, -1,<br class="">file_path +<br class="">wlen, MAX_PATH - wlen)) == 0){<br class="">-        vd_printf("failed converting file_name:%s to WideChar",<br class="">file_name);<br class="">-        return;<br class="">+<br class="">+    const int MAX_ATTEMPTS = 64; // matches behavior of linux<br class="">vdagent<br class="">+    const size_t POSTFIX_LEN = 6; // up to 2 digits in<br class="">parentheses<br class="">and final<br class="">NULL: " (xx)"<br class="">+    size_t name_len = strlen(file_name);<br class="">+    for (attempt = 0; attempt < MAX_ATTEMPTS; attempt++) {<br class="">+        char *pos = &file_name[name_len];<br class="">+        if (attempt > 0) {<br class="">+            if (name_len + POSTFIX_LEN > MAX_PATH) {<br class="">+                vd_printf("failed creating %ls. Postfix makes<br class="">name<br class="">too long<br class="">for the buffer.", file_path);<br class="">+                return;<br class="">+            }<br class="">+            snprintf(pos, POSTFIX_LEN, " (%d)", attempt);<br class="">+        }<br class="">+        if((MultiByteToWideChar(CP_UTF8, 0, file_name, -1,<br class="">file_path + wlen,<br class="">MAX_PATH - wlen)) == 0){<br class="">+            vd_printf("failed converting file_name:%s to<br class="">WideChar",<br class="">file_name);<br class="">+            return;<br class="">+        }<br class="">+        handle = CreateFile(file_path, GENERIC_WRITE, 0, NULL,<br class="">CREATE_NEW,<br class="">0, NULL);<br class="">+        if (handle != INVALID_HANDLE_VALUE) {<br class="">+            break;<br class="">+        }<br class="">+<br class="">+        // If the file already exists, we can re-try with a new<br class="">filename. If<br class="">+        // it's a different error, there's not much we can do.<br class="">+        if (GetLastError() != ERROR_FILE_EXISTS) {<br class=""></blockquote><br class="">I would include the old line:<br class=""><br class="">   vd_printf("failed creating %ls %lu", file_path,<br class="">GetLastError());<br class=""><br class=""><blockquote type="cite" class="">+            return;<br class="">+        }<br class="">     }<br class="">-    handle = CreateFile(file_path, GENERIC_WRITE, 0, NULL,<br class="">CREATE_NEW, 0,<br class="">NULL);<br class="">-    if (handle == INVALID_HANDLE_VALUE) {<br class="">-        vd_printf("failed creating %ls %lu", file_path,<br class="">GetLastError());<br class="">+<br class="">+    if (attempt == MAX_ATTEMPTS) {<br class="">+        vd_printf("Failed creating %ls. More than 63 copies<br class="">exist?",<br class="">file_path);<br class="">         return;<br class="">     }<br class="">+<br class="">     task = new FileXferTask(handle, file_size, file_path);<br class="">     _tasks[start->id] = task;<br class="">     status->result = VD_AGENT_FILE_XFER_STATUS_CAN_SEND_DATA;<br class=""></blockquote><br class="">Frediano<br class=""></blockquote><br class="">_______________________________________________<br class="">Spice-devel mailing list<br class=""><a href="mailto:Spice-devel@lists.freedesktop.org" class="">Spice-devel@lists.freedesktop.org</a><br class=""><a href="https://lists.freedesktop.org/mailman/listinfo/spice-devel" class="">https://lists.freedesktop.org/mailman/listinfo/spice-devel</a><br class=""></blockquote><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Spice-devel mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:Spice-devel@lists.freedesktop.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">Spice-devel@lists.freedesktop.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="https://lists.freedesktop.org/mailman/listinfo/spice-devel" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">https://lists.freedesktop.org/mailman/listinfo/spice-devel</a></div></blockquote></div><br class=""></div></body></html>