# HG changeset patch # User Sean Egan # Date 1197876579 0 # Node ID a3bc0682e98ddcb259268793ad5628db365e5d0a # Parent ce3d42470adfd15dc168bba6a367e6faf670585f Patch from eperez to make writing to buddy icon files atomic. Fixes #3528. diff -r ce3d42470adf -r a3bc0682e98d libpurple/buddyicon.c --- a/libpurple/buddyicon.c Mon Dec 17 06:51:12 2007 +0000 +++ b/libpurple/buddyicon.c Mon Dec 17 07:29:39 2007 +0000 @@ -98,8 +98,7 @@ { const char *dirname; char *path; - FILE *file = NULL; - + g_return_if_fail(img != NULL); if (!purple_buddy_icons_is_caching()) @@ -120,24 +119,12 @@ } } - if ((file = g_fopen(path, "wb")) != NULL) - { - if (!fwrite(purple_imgstore_get_data(img), purple_imgstore_get_size(img), 1, file)) - { - purple_debug_error("buddyicon", "Error writing %s: %s\n", - path, g_strerror(errno)); - } - else - purple_debug_info("buddyicon", "Wrote cache file: %s\n", path); - - fclose(file); - } - else - { + if (!g_file_test(path, G_FILE_TEST_EXISTS)) { + purple_util_write_data_to_file_absolute(path, purple_imgstore_get_data(img), + purple_imgstore_get_size(img)); + } else { purple_debug_error("buddyicon", "Unable to create file %s: %s\n", path, g_strerror(errno)); - g_free(path); - return; } g_free(path); }