From ec64dc73df5f93278f40e80111b0b332549824bc Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Mon, 1 Mar 2004 18:16:33 +0000 Subject: If reading the bookmarks file, or re-importing the bookmarks from the rdf 2004-03-01 Christian Persch * src/bookmarks/ephy-bookmarks.c: (backup_file), (ephy_bookmarks_init): If reading the bookmarks file, or re-importing the bookmarks from the rdf file fails, back up those files so that the user can afterwards try to manually recover his bookmarks. Fixes bug #128308. --- ChangeLog | 9 +++++++++ src/bookmarks/ephy-bookmarks.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/ChangeLog b/ChangeLog index fec5fc8d9..ff5924df3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2004-03-01 Christian Persch + + * src/bookmarks/ephy-bookmarks.c: (backup_file), + (ephy_bookmarks_init): + + If reading the bookmarks file, or re-importing the bookmarks from the + rdf file fails, back up those files so that the user can afterwards + try to manually recover his bookmarks. Fixes bug #128308. + 2004-03-01 Christian Persch * src/bookmarks/ephy-bookmarks-import.c: (xbel_parse_folder), diff --git a/src/bookmarks/ephy-bookmarks.c b/src/bookmarks/ephy-bookmarks.c index f15e20ccd..928813f81 100644 --- a/src/bookmarks/ephy-bookmarks.c +++ b/src/bookmarks/ephy-bookmarks.c @@ -585,6 +585,34 @@ disable_bookmark_editing_notifier (GConfClient *client, update_bookmark_editing (eb); } +static void +backup_file (const char *original_filename, const char *extension) +{ + char *template, *backup_filename; + int result = 0; + + template = g_strconcat (original_filename, ".backup-XXXXXX", NULL); + backup_filename = ephy_file_tmp_filename (template, extension); + + if (backup_filename != NULL) + { + result = rename (original_filename, backup_filename); + } + + if (result >= 0) + { + g_message ("Your old bookmarks file was backed up as \"%s\".\n", + backup_filename); + } + else + { + g_warning ("Backup failed! Your old bookmarks file was lost.\n"); + } + + g_free (template); + g_free (backup_filename); +} + static void ephy_bookmarks_init (EphyBookmarks *eb) { @@ -682,8 +710,20 @@ ephy_bookmarks_init (EphyBookmarks *eb) EPHY_BOOKMARKS_XML_ROOT, EPHY_BOOKMARKS_XML_VERSION) == FALSE) { + /* save the corrupted files so the user can late try to + * manually recover them. See bug #128308. + */ + + g_warning ("Could not read bookmarks file \"%s\", trying to " + "re-import bookmarks from \"%s\"\n", + eb->priv->xml_file, eb->priv->rdf_file); + + backup_file (eb->priv->xml_file, "xml"); + if (ephy_bookmarks_import_rdf (eb, eb->priv->rdf_file) == FALSE) { + backup_file (eb->priv->rdf_file, "rdf"); + eb->priv->init_defaults = TRUE; } } -- cgit v1.2.1