fix for bug #406114: when automatically importing from bookmarks html format, use bookmarks.postplaces.html, if it exists (otherwise, defer to bookmarks.html) r=dietrich, a=damon

This commit is contained in:
2007-12-04 23:14:47 -08:00
parent d8f4b630b3
commit 4207263def
2 changed files with 32 additions and 5 deletions

View File

@@ -359,6 +359,20 @@ BrowserGlue.prototype = {
var bookmarksFile = dirService.get("BMarks", Ci.nsILocalFile);
var overwriteBookmarks =
prefBranch.getBoolPref("browser.bookmarks.overwrite");
// if we don't plan on overwriting bookmarks.html, that means we'll
// be writing to bookmarks.postplaces.html and we could be importing
// because places.sqlite is corrupt or non-existant.
// in this scenario, attempt to use the postplaces first.
if (!overwriteBookmarks) {
bookmarksFile.leafName = "bookmarks.postplaces.html";
// note, it may not exist, and then we should fall back to bookmarks.html
if (!bookmarksFile.exists())
bookmarksFile = dirService.get("BMarks", Ci.nsILocalFile);
}
if (bookmarksFile.exists()) {
// import the file
try {
@@ -372,7 +386,7 @@ BrowserGlue.prototype = {
}
// only back up pre-places bookmarks.html if we plan on overwriting it
if (prefBranch.getBoolPref("browser.bookmarks.overwrite")) {
if (overwriteBookmarks) {
// backup pre-places bookmarks.html
// XXXtodo remove this before betas, after import/export is solid
var profDir = dirService.get("ProfD", Ci.nsILocalFile);

View File

@@ -113,6 +113,7 @@
#define PREF_BROWSER_IMPORT_DEFAULTS "browser.places.importDefaults"
#define PREF_BROWSER_CREATEDSMARTBOOKMARKS "browser.places.createdSmartBookmarks"
#define PREF_BROWSER_LEFTPANEFOLDERID "browser.places.leftPaneFolderId"
#define PREF_BROWSER_BOOKMARKS_OVERWRITE "browser.bookmarks.overwrite"
// Default (integer) value of PREF_DB_CACHE_PERCENTAGE from 0-100
// This is 6% of machine memory, giving 15MB for a user with 256MB of memory.
@@ -509,11 +510,23 @@ nsNavHistory::InitDBFile(PRBool aForceInit)
rv = prefs->SetBoolPref(PREF_BROWSER_IMPORT_DEFAULTS, PR_TRUE);
NS_ENSURE_SUCCESS(rv, rv);
// if the places.sqlite gets deleted/corrupted the queries should be created again
rv = prefs->SetBoolPref(PREF_BROWSER_CREATEDSMARTBOOKMARKS, PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv);
// if the places.sqlite gets deleted/corrupted the "Smart Bookmarks"
// should only be forcibly re-created if we overwriting bookmarks
// (using bookmarks.html instead of bookmarks.postplaces.html)
// if we are using bookmarks.postplaces.html, the "Smart Bookmarks"
// should already exist and be in bookmarks.postplaces.html
PRBool overwriteBookmarks = PR_FALSE;
rv = prefs->GetBoolPref(PREF_BROWSER_BOOKMARKS_OVERWRITE,
&overwriteBookmarks);
NS_ENSURE_SUCCESS(rv, rv);
if (overwriteBookmarks) {
rv = prefs->SetBoolPref(PREF_BROWSER_CREATEDSMARTBOOKMARKS, PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv);
}
// we must create a new Organizer left pane folder root, the old will not be valid anymore
// we must create a new Organizer left pane folder root,
// the old will not be valid anymore
rv = prefs->SetIntPref(PREF_BROWSER_LEFTPANEFOLDERID, -1);
NS_ENSURE_SUCCESS(rv, rv);
}