pidgin: cc588e79: Uniquify auto-accepted file names to foo...
resiak at pidgin.im
resiak at pidgin.im
Sat Sep 6 12:45:46 EDT 2008
-----------------------------------------------------------------
Revision: cc588e79152601781e53c9386f48bb14154b063e
Ancestor: 276af715e3b26cba28965e1fa14e8c6e5ac65a85
Author: resiak at pidgin.im
Date: 2008-09-05T14:32:00
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/cc588e79152601781e53c9386f48bb14154b063e
Modified files:
libpurple/plugins/autoaccept.c
ChangeLog:
Uniquify auto-accepted file names to foo-2.tar.gz, not foo.tar.gz-2.
Fixes a recently-filed bug whose number I didn't look up before getting onto
the train.
Comments:
Fixes #6890
-------------- next part --------------
============================================================
--- libpurple/plugins/autoaccept.c 935f4ead922da9429038f3bfcdd74add2f5c648e
+++ libpurple/plugins/autoaccept.c 648ab517f31ecdf43ee1f517f4836506be8a55b3
@@ -117,6 +117,9 @@ file_recv_request_cb(PurpleXfer *xfer, g
{
int count = 1;
const char *escape;
+ gchar **name_and_ext;
+ const gchar *name;
+ gchar *ext;
if (purple_prefs_get_bool(PREF_NEWDIR))
dirname = g_build_filename(pref, purple_normalize(account, xfer->who), NULL);
@@ -132,9 +135,24 @@ file_recv_request_cb(PurpleXfer *xfer, g
escape = purple_escape_filename(xfer->filename);
filename = g_build_filename(dirname, escape, NULL);
+ /* Split at the first dot, to avoid uniquifying "foo.tar.gz" to "foo.tar-2.gz" */
+ name_and_ext = g_strsplit(escape, ".", 2);
+ name = name_and_ext[0];
+ g_return_if_fail(name != NULL);
+ if (name_and_ext[1] != NULL) {
+ /* g_strsplit does not include the separator in each chunk. */
+ ext = g_strdup_printf(".%s", name_and_ext[1]);
+ } else {
+ ext = g_strdup("");
+ }
+
/* Make sure the file doesn't exist. Do we want some better checking than this? */
+ /* FIXME: There is a race here: if the newly uniquified file name gets created between
+ * this g_file_test and the transfer starting, the file created in the meantime
+ * will be clobbered. But it's not at all straightforward to fix.
+ */
while (g_file_test(filename, G_FILE_TEST_EXISTS)) {
- char *file = g_strdup_printf("%s-%d", escape, count++);
+ char *file = g_strdup_printf("%s-%d%s", name, count++, ext);
g_free(filename);
filename = g_build_filename(dirname, file, NULL);
g_free(file);
@@ -142,6 +160,8 @@ file_recv_request_cb(PurpleXfer *xfer, g
purple_xfer_request_accepted(xfer, filename);
+ g_strfreev(name_and_ext);
+ g_free(ext);
g_free(dirname);
g_free(filename);
}
More information about the Commits
mailing list