changeset 9747:e0060f3b6d92

[gaim-migrate @ 10613] relative buddy icon paths instead of absolute ones from nosnilmot. this should save some headaches migrating a ~/.gaim around committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Sat, 14 Aug 2004 13:55:41 +0000
parents 3a71d70e3945
children e2aeba6a79e0
files src/buddyicon.c
diffstat 1 files changed, 26 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/buddyicon.c	Fri Aug 13 23:22:27 2004 +0000
+++ b/src/buddyicon.c	Sat Aug 14 13:55:41 2004 +0000
@@ -205,6 +205,7 @@
 	char *filename;
 	const char *old_icon;
 	size_t len;
+	struct stat st;
 	FILE *file = NULL;
 
 	g_return_if_fail(icon  != NULL);
@@ -220,8 +221,6 @@
 	filename = g_build_filename(dirname, random, NULL);
 	old_icon = gaim_blist_node_get_string((GaimBlistNode*)buddy, "buddy_icon");
 
-	g_free(random);
-
 	if (!g_file_test(dirname, G_FILE_TEST_IS_DIR))
 	{
 		gaim_debug_info("buddy icons", "Creating icon cache directory.\n");
@@ -240,12 +239,23 @@
 		fclose(file);
 	}
 
-	if (old_icon != NULL)
-		unlink(old_icon);
+	g_free(filename);
 
-	gaim_blist_node_set_string((GaimBlistNode *)buddy, "buddy_icon", filename);
+	if (old_icon != NULL)
+	{
+		if(!stat(old_icon, &st))
+			unlink(old_icon);
+		else {
+			filename = g_build_filename(dirname, random, NULL);
+			if(!stat(filename, &st))
+				unlink(filename);
+			g_free(filename);
+		}
+	}
 
-	g_free(filename);
+	gaim_blist_node_set_string((GaimBlistNode *)buddy, "buddy_icon", random);
+
+	g_free(random);
 }
 
 void
@@ -345,6 +355,7 @@
 {
 	GHashTable *icon_cache;
 	GaimBuddyIcon *ret = NULL;
+	char *filename = NULL;
 
 	g_return_val_if_fail(account  != NULL, NULL);
 	g_return_val_if_fail(username != NULL, NULL);
@@ -362,8 +373,13 @@
 		if ((file = gaim_blist_node_get_string((GaimBlistNode*)b, "buddy_icon")) == NULL)
 			return NULL;
 
-		if (!stat(file, &st)) {
-			FILE *f = fopen(file, "rb");
+		if (!stat(file, &st))
+			filename = g_strdup(file);
+		else
+			filename = g_build_filename(gaim_buddy_icons_get_cache_dir(), file, NULL);
+
+		if (!stat(filename, &st)) {
+			FILE *f = fopen(filename, "rb");
 			if (f) {
 				char *data = g_malloc(st.st_size);
 				fread(data, 1, st.st_size, f);
@@ -373,9 +389,11 @@
 				gaim_buddy_icon_set_data(ret, data, st.st_size);
 				gaim_buddy_icon_unref(ret);
 				g_free(data);
+				g_free(filename);
 				return ret;
 			}
 		}
+		g_free(filename);
 	}
 
 	return ret;