changeset 8826:c0f5132fd5a3

[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. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Mon, 26 Apr 2004 20:33:31 +0000
parents 190a5f7f9524
children 408f56cd5cf9
files src/blist.c
diffstat 1 files changed, 20 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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);
 		}