[Spice-devel] [PATCH vd_agent_linux 7/7] file-xfer: Do not strip filename if file part has no extension
Frediano Ziglio
fziglio at redhat.com
Tue Jan 15 18:50:02 UTC 2019
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
src/tests/test-file-xfers.c | 6 ++++++
src/vdagent/file-xfers.c | 3 ++-
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/src/tests/test-file-xfers.c b/src/tests/test-file-xfers.c
index 494adc9..e87efac 100644
--- a/src/tests/test-file-xfers.c
+++ b/src/tests/test-file-xfers.c
@@ -67,6 +67,12 @@ int main(int argc, char *argv[])
// try to create a file with a path where there's a file (should fail)
test_file("test.txt/out", NULL);
+ // create a file without extension in a directory with extension
+ test_file("sub.dir/test", "./test-dir/sub.dir/test");
+
+ // create a file with same name above, should not strip the filename
+ test_file("sub.dir/test", "./test-dir/sub.dir/test (1)");
+
assert(system("rm -rf test-dir") == 0);
return 0;
diff --git a/src/vdagent/file-xfers.c b/src/vdagent/file-xfers.c
index a26ee46..3b431ee 100644
--- a/src/vdagent/file-xfers.c
+++ b/src/vdagent/file-xfers.c
@@ -206,7 +206,8 @@ vdagent_file_xfers_create_file(const char *save_dir, char **file_name_p)
goto error;
}
g_free(path);
- char *extension = strrchr(file_path, '.');
+ char *extension = strrchr(file_path, '/');
+ extension = strrchr(extension != NULL ? extension + 1 : file_path, '.');
int basename_len = extension != NULL ? extension - file_path : strlen(file_path);
path = g_strdup_printf("%.*s (%i)%s", basename_len, file_path,
i + 1, extension ? extension : "");
--
2.20.1
More information about the Spice-devel
mailing list