changeset 21321:12d6b551fb6a

Actually properly fix this gg "write my buddy list to a file" callback by just using purple_util_write_data_to_file_absolute().
author Will Thompson <will.thompson@collabora.co.uk>
date Sun, 11 Nov 2007 16:50:24 +0000
parents 85fbadb8b8fd
children 93e9e022a470
files libpurple/protocols/gg/gg.c
diffstat 1 files changed, 12 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/gg/gg.c	Sun Nov 11 14:18:23 2007 +0000
+++ b/libpurple/protocols/gg/gg.c	Sun Nov 11 16:50:24 2007 +0000
@@ -254,16 +254,14 @@
 /*
  */
 /* static void ggp_callback_buddylist_save_ok(PurpleConnection *gc, const char *file) {{{ */
-static void ggp_callback_buddylist_save_ok(PurpleConnection *gc, const char *file)
+static void ggp_callback_buddylist_save_ok(PurpleConnection *gc, const char *filename)
 {
 	PurpleAccount *account = purple_connection_get_account(gc);
 
-	FILE *fh;
 	char *buddylist = ggp_buddylist_dump(account);
-	gchar *msg;
 
 	purple_debug_info("gg", "Saving...\n");
-	purple_debug_info("gg", "file = %s\n", file);
+	purple_debug_info("gg", "file = %s\n", filename);
 
 	if (buddylist == NULL) {
 		purple_notify_info(account, _("Save Buddylist..."),
@@ -272,30 +270,18 @@
 		return;
 	}
 
-	if ((fh = g_fopen(file, "wb")) == NULL) {
-		msg = g_strconcat(_("Couldn't open file"), ": ", file, "\n", NULL);
-		purple_debug_error("gg", "Could not open file: %s\n", file);
-		purple_notify_error(account, _("Couldn't open file"), msg, NULL);
-		g_free(msg);
-		g_free(buddylist);
-		return;
+	if(purple_util_write_data_to_file_absolute(filename, buddylist, -1)) {
+		purple_notify_info(account, _("Save Buddylist..."),
+			 _("Buddylist saved successfully!"), NULL);
+	} else {
+		gchar *primary = g_strdup_printf(
+			_("Couldn't write buddy list for %s to %s"),
+			purple_account_get_username(account), filename);
+		purple_notify_error(account, _("Couldn't save buddy list"),
+			primary, NULL);
+		g_free(primary);
 	}
 
-	if (!fwrite(buddylist, sizeof(char), g_utf8_strlen(buddylist, -1), fh)) {
-		const gchar *err = g_strerror(errno);
-		gchar *title = g_strdup_printf(
-			_("Couldn't write buddylist to %s"), err);
-
-		purple_debug_error("gg", "Error writing %s: %s\n", file, err);
-		purple_notify_error(account, title, title, err);
-
-		g_free(title);
-	} else {
-		purple_notify_info(account, _("Save Buddylist..."),
-			 _("Buddylist saved successfully!"), NULL);
-	}
-
-	fclose(fh);
 	g_free(buddylist);
 }
 /* }}} */