Patch from eperez to make writing to buddy icon files atomic. Fixes #3528.

Mon, 17 Dec 2007 07:29:39 +0000

author
Sean Egan <seanegan@pidgin.im>
date
Mon, 17 Dec 2007 07:29:39 +0000
changeset 21958
666685c4f8a9
parent 21957
0ce77f86c7f3
child 21959
a20e87ea2403

Patch from eperez to make writing to buddy icon files atomic. Fixes #3528.

libpurple/buddyicon.c file | annotate | diff | comparison | revisions
--- 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);
 }

mercurial