Fix for bug 445704 (JSON bookmarks backup has localized filename (and can't be easily restored). r=zeniko, a=beltzner.

This commit is contained in:
Dietrich Ayala 2008-11-13 17:54:25 +01:00
Родитель 9b47518430
Коммит 705834c398
3 изменённых файлов: 21 добавлений и 9 удалений

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

@ -415,11 +415,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);
}
@ -435,8 +438,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);

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

@ -1585,17 +1585,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);

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

@ -11,8 +11,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