X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-utils.c;h=33b5a049def867e02bbb09ccd20a96f367a821db;hp=9b1178f7719d92b2ba2be6b0f34e112b42a08950;hb=478cd210e150978c4f80d9785ca2d2803ea28192;hpb=b7507d83f705d2c40a64dbe1eb3fcabf8edccd0e diff --git a/src/modest-utils.c b/src/modest-utils.c index 9b1178f..33b5a04 100644 --- a/src/modest-utils.c +++ b/src/modest-utils.c @@ -133,13 +133,13 @@ modest_utils_create_temp_stream (const gchar *orig_name, const gchar *hash_base, __FUNCTION__, orig_name); return NULL; } - + if (g_strstr_len (orig_name, strlen(orig_name), "/") != NULL) { g_warning ("%s: filename contains '/' character(s) (%s)", __FUNCTION__, orig_name); return NULL; } - + /* make a random subdir under /tmp or /var/tmp */ if (hash_base != NULL) { hash_number = g_str_hash (hash_base); @@ -155,6 +155,12 @@ modest_utils_create_temp_stream (const gchar *orig_name, const gchar *hash_base, } filepath = g_strconcat (tmpdir, "/", orig_name, NULL); + + /* if file exists, first we try to remove it */ + if (modest_utils_file_exists (filepath)) { + g_unlink (filepath); + } + /* don't overwrite if it already exists, even if it is writable */ if (modest_utils_file_exists (filepath)) { if (path!=NULL) { @@ -169,7 +175,7 @@ modest_utils_create_temp_stream (const gchar *orig_name, const gchar *hash_base, fd = g_open (filepath, O_CREAT|O_WRONLY|O_TRUNC, 0644); if (fd == -1) { g_warning ("%s: failed to create '%s': %s", - __FUNCTION__, filepath, g_strerror(errno)); + __FUNCTION__, filepath, g_strerror(errno)); g_free (filepath); g_free (tmpdir); return NULL; @@ -180,6 +186,8 @@ modest_utils_create_temp_stream (const gchar *orig_name, const gchar *hash_base, if (path) *path = filepath; + else + g_free (filepath); return TNY_FS_STREAM (tny_fs_stream_new (fd)); } @@ -671,7 +679,7 @@ launch_sort_headers_dialog (GtkWindow *parent_window, void modest_utils_run_sort_dialog (GtkWindow *parent_window, - ModestSortDialogType type) + ModestSortDialogType type) { GtkWidget *dialog = NULL;