[Spice-devel] [PATCH linux vdagent] file-xfer: use better names for duplicate files

Victor Toso victortoso at redhat.com
Fri Apr 28 06:50:08 UTC 2017


Hi,

On Thu, Apr 27, 2017 at 04:16:31PM -0500, Jonathon Jongsma wrote:
> When transferring the same file multiple times, the vdagent tries to
> avoid overwriting an existing file on the guest by appending an integer
> to the filename. Instead of just appending the integer to the very end,
> we now try to be smarter and append the integer before the file
> extension. For example, if we transferred the file "file.doc" twice, the
> second copy would have become "file.doc (1)". It is now "file (1).doc".
> This matches more closely with the behavior of the Nautilus file manager
> as well.
> 
> Signed-off-by: Jonathon Jongsma <jjongsma at redhat.com>
> ---
>  src/vdagent/file-xfers.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/src/vdagent/file-xfers.c b/src/vdagent/file-xfers.c
> index b3937a4..8fc33db 100644
> --- a/src/vdagent/file-xfers.c
> +++ b/src/vdagent/file-xfers.c
> @@ -202,7 +202,10 @@ void vdagent_file_xfers_start(struct vdagent_file_xfers *xfers,
>      path = g_strdup(file_path);
>      for (i = 0; i < 64 && (stat(path, &st) == 0 || errno != ENOENT); i++) {
>          g_free(path);
> -        path = g_strdup_printf("%s (%d)", file_path, i + 1);
> +        char *extension = strrchr(file_path, '.');
> +        int basename_len = extension != NULL ? extension - file_path : -1;
> +        path = g_strdup_printf("%*s (%i)%s", basename_len, file_path,
> +                               i + 1, extension ? extension : "");

I would add a small comment like "Adding an integer before the file
extension" in this block.

In the linux vdagent code, I don't see often variables being declared in
the middle of the code block.

Other than that, patch looks fine to me.

>      }
>      g_free(task->file_name);
>      task->file_name = path;
> -- 
> 2.9.3
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20170428/33333f45/attachment.sig>


More information about the Spice-devel mailing list