From 42951db312fa8a0491a98cb33eb9c29c0ac8db48 Mon Sep 17 00:00:00 2001 From: "dietrich%mozilla.com" Date: Tue, 21 Apr 2009 00:49:05 +0000 Subject: [PATCH] Bug 445704 - JSON bookmarks backup has localized filename (and can't be easily restored) (r=mano, a=dveditz) git-svn-id: svn://10.0.0.236/trunk@256991 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/browser/components/places/content/places.js | 9 ++++++--- mozilla/toolkit/components/places/src/utils.js | 13 +++++++++++-- .../locales/en-US/chrome/places/places.properties | 8 ++++---- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/mozilla/browser/components/places/content/places.js b/mozilla/browser/components/places/content/places.js index d47d9d489b6..5680f0502c7 100755 --- a/mozilla/browser/components/places/content/places.js +++ b/mozilla/browser/components/places/content/places.js @@ -416,11 +416,14 @@ var PlacesOrganizer = { restorePopup.removeChild(restorePopup.firstChild); // get list of files + var localizedFilename = PlacesUtils.getString("bookmarksArchiveFilename"); + var localizedFilenamePrefix = localizedFilename.substr(0, localizedFilename.indexOf("-")); var fileList = []; var files = this.bookmarksBackupDir.directoryEntries; while (files.hasMoreElements()) { var f = files.getNext().QueryInterface(Ci.nsIFile); - if (!f.isHidden() && f.leafName.match(/^bookmarks-.+json$/)) + var rx = new RegExp("^(bookmarks|" + localizedFilenamePrefix + ")-.+\.json"); + if (!f.isHidden() && f.leafName.match(rx)) fileList.push(f); } @@ -436,8 +439,8 @@ var PlacesOrganizer = { var m = restorePopup.insertBefore (document.createElement("menuitem"), document.getElementById("restoreFromFile")); - var dateStr = fileList[i].leafName.replace("bookmarks-", ""). - replace(/\.json$/, ""); + var rx = new RegExp("^(bookmarks|" + localizedFilenamePrefix + ")-"); + var dateStr = fileList[i].leafName.replace(rx, "").replace(/\.json$/, ""); if (!dateStr.length) dateStr = fileList[i].leafName; m.setAttribute("label", dateStr); diff --git a/mozilla/toolkit/components/places/src/utils.js b/mozilla/toolkit/components/places/src/utils.js index b17067323d5..eae72a34add 100644 --- a/mozilla/toolkit/components/places/src/utils.js +++ b/mozilla/toolkit/components/places/src/utils.js @@ -1594,17 +1594,26 @@ var PlacesUtils = { // Use YYYY-MM-DD (ISO 8601) as it doesn't contain illegal characters // and makes the alphabetical order of multiple backup files more useful. var date = new Date().toLocaleFormat("%Y-%m-%d"); - var backupFilename = this.getFormattedString("bookmarksArchiveFilename", [date]); + var backupFilename = "bookmarks-" + date + ".json"; var backupFile = null; if (!aForceArchive) { var backupFileNames = []; var backupFilenamePrefix = backupFilename.substr(0, backupFilename.indexOf("-")); + + // Get the localized backup filename, to clear out + // old backups with a localized name (bug 445704). + var localizedFilename = this.getFormattedString("bookmarksArchiveFilename", [date]); + var localizedFilenamePrefix = localizedFilename.substr(0, localizedFilename.indexOf("-")); + var rx = new RegExp("^(bookmarks|" + localizedFilenamePrefix + ")-.+\.json"); + var entries = bookmarksBackupDir.directoryEntries; while (entries.hasMoreElements()) { var entry = entries.getNext().QueryInterface(Ci.nsIFile); var backupName = entry.leafName; - if (backupName.substr(0, backupFilenamePrefix.length) == backupFilenamePrefix) { + // A valid backup is any file that matches either the localized or + // not-localized filename (bug 445704). + if (backupName.match(rx)) { if (backupName == backupFilename) backupFile = entry; backupFileNames.push(backupName); diff --git a/mozilla/toolkit/locales/en-US/chrome/places/places.properties b/mozilla/toolkit/locales/en-US/chrome/places/places.properties index 529416eb06c..02eb9432b83 100644 --- a/mozilla/toolkit/locales/en-US/chrome/places/places.properties +++ b/mozilla/toolkit/locales/en-US/chrome/places/places.properties @@ -14,8 +14,8 @@ finduri-AgeInDays-isgreater=Older than %S days localhost=(local files) # LOCALIZATION NOTE (bookmarksArchiveFilename): -# %S will be replaced by the current date in ISO 8601 format, YYYY-MM-DD. -# The resulting string will be suggested as a filename, so make sure that you're -# only using characters legal for file names. Consider falling back to the -# en-US value if you have to use non-ascii characters. +# Do not change this string! It's used only to +# detect older localized bookmark archives from +# before bug 445704 was fixed. It will be removed +# in a subsequent release. bookmarksArchiveFilename=bookmarks-%S.json