Bug 464767 - do not overwrite existing bookmarks if importBookmarksHTML is true but there's no bookmarks.html file (r=dietrich, a=beltzner)

This commit is contained in:
mak77@bonardo.net 2008-11-18 09:25:39 -08:00
Родитель ef32c8f8ae
Коммит 0b15d06d9f
1 изменённых файлов: 20 добавлений и 15 удалений

Просмотреть файл

@ -539,27 +539,32 @@ BrowserGlue.prototype = {
// ensurePlacesDefaultQueriesInitialized() is called by import.
this._prefs.setIntPref("browser.places.smartBookmarksVersion", 0);
// Get bookmarks folder
// Get bookmarks.html file location
var dirService = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties);
var bookmarksFile = dirService.get("BMarks", Ci.nsILocalFile);
// User wants to restore default bookmarks
if (restoreDefaultBookmarks || !bookmarksFile.exists()) {
// get bookmarks.html file from default profile folder
bookmarksFile = dirService.get("profDef", Ci.nsILocalFile);
bookmarksFile.append("bookmarks.html");
var bookmarksFile = null;
if (restoreDefaultBookmarks) {
// User wants to restore bookmarks.html file from default profile folder
bookmarksFile = dirService.get("profDef", Ci.nsILocalFile)
.append("bookmarks.html");
}
else
bookmarksFile = dirService.get("BMarks", Ci.nsILocalFile);
// import the file
try {
var importer = Cc["@mozilla.org/browser/places/import-export-service;1"].
getService(Ci.nsIPlacesImportExportService);
importer.importHTMLFromFile(bookmarksFile, true /* overwrite existing */);
} catch (err) {
// Report the error, but ignore it.
Cu.reportError(err);
if (bookmarksFile.exists()) {
// import the file
try {
var importer = Cc["@mozilla.org/browser/places/import-export-service;1"].
getService(Ci.nsIPlacesImportExportService);
importer.importHTMLFromFile(bookmarksFile, true /* overwrite existing */);
} catch (err) {
// Report the error, but ignore it.
Cu.reportError("Bookmarks.html file could be corrupt. " + err);
}
}
else
Cu.reportError("Unable to find bookmarks.html file.");
// Reset preferences, so we won't try to import again at next run
if (importBookmarksHTML)