changeset 16543:175eadaead53

nosnilmot had a problem with empty icon files.
author Richard Laager <rlaager@wiktel.com>
date Sat, 28 Apr 2007 02:24:40 +0000
parents ec8a3ca95a13
children e98cd6ed5c13 317f3ae0ef93
files libpurple/buddyicon.c
diffstat 1 files changed, 19 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/buddyicon.c	Sat Apr 28 00:15:46 2007 +0000
+++ b/libpurple/buddyicon.c	Sat Apr 28 02:24:40 2007 +0000
@@ -850,6 +850,18 @@
 }
 
 static void
+delete_buddy_icon_settings(PurpleBlistNode *node, const char *setting_name)
+{
+	purple_blist_node_remove_setting(node, setting_name);
+
+	if (!strcmp(setting_name, "buddy_icon"))
+	{
+		purple_blist_node_remove_setting(node, "avatar_hash");
+		purple_blist_node_remove_setting(node, "icon_checksum");
+	}
+}
+
+static void
 migrate_buddy_icon(PurpleBlistNode *node, const char *setting_name,
                    const char *dirname, const char *filename)
 {
@@ -877,8 +889,10 @@
 		FILE *file;
 		char *new_filename;
 
-		if (!read_icon_file(path, &icon_data, &icon_len))
+		if (!read_icon_file(path, &icon_data, &icon_len) ||
+		    icon_data == NULL || icon_len > 0)
 		{
+			delete_buddy_icon_settings(node, setting_name);
 			g_free(path);
 			return;
 		}
@@ -888,6 +902,7 @@
 		new_filename = purple_buddy_icon_data_calculate_filename(icon_data, icon_len);
 		if (new_filename == NULL)
 		{
+			delete_buddy_icon_settings(node, setting_name);
 			return;
 		}
 
@@ -910,6 +925,8 @@
 			                   path, strerror(errno));
 			g_free(new_filename);
 			g_free(path);
+
+			delete_buddy_icon_settings(node, setting_name);
 			return;
 		}
 		g_free(path);
@@ -947,16 +964,7 @@
 	else
 	{
 		/* If the icon is gone, drop the setting... */
-		purple_blist_node_remove_setting(node,
-		                                 setting_name);
-
-		if (!strcmp(setting_name, "buddy_icon"))
-		{
-			purple_blist_node_remove_setting(node,
-			                                 "avatar_hash");
-			purple_blist_node_remove_setting(node,
-			                                 "icon_checksum");
-		}
+		delete_buddy_icon_settings(node, setting_name);
 		g_free(path);
 	}
 }