Bug 971686 - Bookmarks backups can't be properly stored if /tmp is on a different filesystem. r=Yoric

This commit is contained in:
Marco Bonardo 2014-02-14 15:42:35 +01:00
parent b14951c9ee
commit e802c76f4b
2 changed files with 12 additions and 4 deletions

View File

@ -99,10 +99,11 @@ this.BookmarkJSONUtils = Object.freeze({
Components.utils.reportError("Unable to report telemetry.");
}
// Write to the temp folder first, to avoid leaving back partial files.
let tmpPath = OS.Path.join(OS.Constants.Path.tmpDir,
OS.Path.basename(aFilePath) + ".tmp");
yield OS.File.writeAtomic(aFilePath, jsonString, { tmpPath: tmpPath });
// Do not write to the tmp folder, otherwise if it has a different
// filesystem writeAtomic will fail. Eventual dangling .tmp files should
// be cleaned up by the caller.
yield OS.File.writeAtomic(aFilePath, jsonString,
{ tmpPath: OS.Path.join(aFilePath + ".tmp") });
return count;
});
},

View File

@ -132,6 +132,13 @@ this.PlacesBackups = {
let backupFolderPath = yield this.getBackupFolder();
let iterator = new OS.File.DirectoryIterator(backupFolderPath);
yield iterator.forEach(function(aEntry) {
// Since this is a lazy getter and OS.File I/O is serialized, we can
// safely remove .tmp files without risking to remove ongoing backups.
if (aEntry.name.endsWith(".tmp")) {
OS.File.remove(aEntry.path);
return;
}
let matches = aEntry.name.match(this._filenamesRegex);
if (matches) {
// Remove bogus backups in future dates.