Mercurial > pidgin.yaz
changeset 21783:3b1d7caddc27
Do not overwrite an existing file. Closes #3982.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Wed, 05 Dec 2007 07:34:11 +0000 |
parents | bacb8c59230a |
children | 3fdd39411e3e |
files | libpurple/plugins/autoaccept.c |
diffstat | 1 files changed, 12 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/plugins/autoaccept.c Wed Dec 05 04:59:43 2007 +0000 +++ b/libpurple/plugins/autoaccept.c Wed Dec 05 07:34:11 2007 +0000 @@ -114,6 +114,8 @@ case FT_ACCEPT: if (ensure_path_exists(pref)) { + int count = 1; + const char *escape; dirname = g_build_filename(pref, purple_normalize(account, xfer->who), NULL); if (!ensure_path_exists(dirname)) @@ -122,8 +124,16 @@ break; } - filename = g_build_filename(dirname, - purple_escape_filename(xfer->filename), NULL); + escape = purple_escape_filename(xfer->filename); + filename = g_build_filename(dirname, escape, NULL); + + /* Make sure the file doesn't exist. Do we want some better checking than this? */ + while (g_file_test(filename, G_FILE_TEST_EXISTS)) { + char *file = g_strdup_printf("%s-%d", escape, count++); + g_free(filename); + filename = g_build_filename(dirname, file, NULL); + g_free(file); + } purple_xfer_request_accepted(xfer, filename);