[gaim-migrate @ 9590]

Mon, 26 Apr 2004 20:33:31 +0000

author
Sean Egan <seanegan@pidgin.im>
date
Mon, 26 Apr 2004 20:33:31 +0000
changeset 8826
c70765d357d2
parent 8825
778e24b7486d
child 8827
b8587411de62

[gaim-migrate @ 9590]
If you're careless like me, and screw up hand-editing your blist.xml you
won't be in the same boat I am, having your entire blist obliterated as this
commit will back the file up to blist.xml~ before obliterating it.

src/blist.c file | annotate | diff | comparison | revisions
--- a/src/blist.c	Mon Apr 26 19:19:14 2004 +0000
+++ b/src/blist.c	Mon Apr 26 20:33:31 2004 +0000
@@ -2137,14 +2137,29 @@
 	}
 
 	gaim = xmlnode_from_str(contents, length);
-	g_free(contents);
-
+	
 	if(!gaim) {
+		FILE *backup;
+		char *name;
 		gaim_debug(GAIM_DEBUG_ERROR, "blist import", "Error parsing %s\n",
 				filename);
+		name = g_build_filename(gaim_user_dir(), "blist.xml~", NULL);
+
+		if((backup = fopen(name, "w"))) {
+			fwrite(contents, length, 1, backup);
+			fclose(backup);
+			chmod(name, S_IRUSR | S_IWUSR);
+		} else {
+			gaim_debug(GAIM_DEBUG_ERROR, "blist load", "Unable to write backup %s\n",
+				   name);
+		}
+		g_free(name);
+		g_free(contents);
 		return FALSE;
 	}
-
+	
+	g_free(contents);
+	
 	blist = xmlnode_get_child(gaim, "blist");
 	if(blist) {
 		xmlnode *groupnode;
@@ -2218,7 +2233,8 @@
 	if(g_file_test(filename, G_FILE_TEST_EXISTS)) {
 		if(!gaim_blist_read(filename)) {
 			msg = g_strdup_printf(_("An error was encountered parsing your "
-						"buddy list.  It has not been loaded."));
+						"buddy list.  It has not been loaded, "
+						"and the old file has moved to blist.xml~."));
 			gaim_notify_error(NULL, NULL, _("Buddy List Error"), msg);
 			g_free(msg);
 		}

mercurial