Backed out changeset db75491e5d2e (bug 1649604) for causing xpcshell and marionette failures. CLOSED TREE

This commit is contained in:
Butkovits Atila 2021-01-25 19:24:06 +02:00
Родитель 359cb93309
Коммит 7924475341
2 изменённых файлов: 48 добавлений и 42 удалений

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

@ -4,9 +4,6 @@
"use strict"; "use strict";
const { PushDB, PushService, PushServiceWebSocket } = serviceExports; const { PushDB, PushService, PushServiceWebSocket } = serviceExports;
// Create the profile directory early to ensure pushBroadcastService
// is initialized with the correct path
do_get_profile();
const { BroadcastService } = ChromeUtils.import( const { BroadcastService } = ChromeUtils.import(
"resource://gre/modules/PushBroadcastService.jsm", "resource://gre/modules/PushBroadcastService.jsm",
null null
@ -26,6 +23,7 @@ const userAgentID = "bd744428-f125-436a-b6d0-dd0c9845837f";
const channelID = "0ef2ad4a-6c49-41ad-af6e-95d2425276bf"; const channelID = "0ef2ad4a-6c49-41ad-af6e-95d2425276bf";
function run_test() { function run_test() {
do_get_profile();
setPrefs({ setPrefs({
userAgentID, userAgentID,
alwaysConnect: true, alwaysConnect: true,

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

@ -51,6 +51,7 @@ ChromeUtils.defineModuleGetter(
"FileUtils", "FileUtils",
"resource://gre/modules/FileUtils.jsm" "resource://gre/modules/FileUtils.jsm"
); );
ChromeUtils.defineModuleGetter(this, "OS", "resource://gre/modules/osfile.jsm");
ChromeUtils.defineModuleGetter( ChromeUtils.defineModuleGetter(
this, this,
"NetUtil", "NetUtil",
@ -61,6 +62,10 @@ XPCOMUtils.defineLazyGetter(this, "gTextDecoder", function() {
return new TextDecoder(); return new TextDecoder();
}); });
XPCOMUtils.defineLazyGetter(this, "gTextEncoder", function() {
return new TextEncoder();
});
const FileInputStream = Components.Constructor( const FileInputStream = Components.Constructor(
"@mozilla.org/network/file-input-stream;1", "@mozilla.org/network/file-input-stream;1",
"nsIFileInputStream", "nsIFileInputStream",
@ -133,11 +138,11 @@ function JSONFile(config) {
this._options = {}; this._options = {};
if (config.compression) { if (config.compression) {
this._options.decompress = this._options.compress = true; this._options.compression = config.compression;
} }
if (config.backupTo) { if (config.backupTo) {
this._options.backupFile = config.backupTo; this._options.backupTo = config.backupTo;
} }
this._finalizeAt = config.finalizeAt || AsyncShutdown.profileBeforeChange; this._finalizeAt = config.finalizeAt || AsyncShutdown.profileBeforeChange;
@ -218,12 +223,14 @@ JSONFile.prototype = {
let data = {}; let data = {};
try { try {
data = await IOUtils.readJSON(this.path, this._options); let bytes = await OS.File.read(this.path, this._options);
// If synchronous loading happened in the meantime, exit now. // If synchronous loading happened in the meantime, exit now.
if (this.dataReady) { if (this.dataReady) {
return; return;
} }
data = JSON.parse(gTextDecoder.decode(bytes));
} catch (ex) { } catch (ex) {
// If an exception occurs because the file does not exist or it cannot be read, // If an exception occurs because the file does not exist or it cannot be read,
// we do two things. // we do two things.
@ -236,7 +243,7 @@ JSONFile.prototype = {
// In the event that the file exists, but an exception is thrown because it cannot be read, // In the event that the file exists, but an exception is thrown because it cannot be read,
// we store it as a .corrupt file for debugging purposes. // we store it as a .corrupt file for debugging purposes.
let cleansedBasename = PathUtils.filename(this.path) let cleansedBasename = OS.Path.basename(this.path)
.replace(/\.json$/, "") .replace(/\.json$/, "")
.replaceAll(/[^a-zA-Z0-9_.]/g, ""); .replaceAll(/[^a-zA-Z0-9_.]/g, "");
let errorNo = ex.winLastError || ex.unixErrno; let errorNo = ex.winLastError || ex.unixErrno;
@ -245,29 +252,30 @@ JSONFile.prototype = {
cleansedBasename, cleansedBasename,
errorNo ? errorNo.toString() : "" errorNo ? errorNo.toString() : ""
); );
if (!(ex instanceof DOMException && ex.name == "NotFoundError")) { if (!(ex instanceof OS.File.Error && ex.becauseNoSuchFile)) {
Cu.reportError(ex); Cu.reportError(ex);
// Move the original file to a backup location, ignoring errors. // Move the original file to a backup location, ignoring errors.
try { try {
let uniquePath = await PathUtils.createUniquePath( let openInfo = await OS.File.openUnique(this.path + ".corrupt", {
this.path + ".corrupt" humanReadable: true,
); });
await IOUtils.move(this.path, uniquePath); await openInfo.file.close();
await OS.File.move(this.path, openInfo.path);
this._recordTelemetry("load", cleansedBasename, "invalid_json"); this._recordTelemetry("load", cleansedBasename, "invalid_json");
} catch (e2) { } catch (e2) {
Cu.reportError(e2); Cu.reportError(e2);
} }
} }
if (this._options.backupFile) { if (this._options.backupTo) {
// Restore the original file from the backup here so fresh writes to empty // Restore the original file from the backup here so fresh writes to empty
// json files don't happen at any time in the future compromising the backup // json files don't happen at any time in the future compromising the backup
// in the process. // in the process.
try { try {
await IOUtils.copy(this._options.backupFile, this.path); await OS.File.copy(this._options.backupTo, this.path);
} catch (e) { } catch (e) {
if (!(e instanceof DOMException && e.name == "NotFoundError")) { if (!(e instanceof OS.File.Error && ex.becauseNoSuchFile)) {
Cu.reportError(e); Cu.reportError(e);
} }
} }
@ -276,24 +284,23 @@ JSONFile.prototype = {
// We still read from the backup file here instead of the original file in case // We still read from the backup file here instead of the original file in case
// access to the original file is blocked, e.g. by anti-virus software on the // access to the original file is blocked, e.g. by anti-virus software on the
// user's computer. // user's computer.
data = await IOUtils.readJSON( let bytes = await OS.File.read(this._options.backupTo, this._options);
this._options.backupFile,
this._options
);
// If synchronous loading happened in the meantime, exit now. // If synchronous loading happened in the meantime, exit now.
if (this.dataReady) { if (this.dataReady) {
return; return;
} }
data = JSON.parse(gTextDecoder.decode(bytes));
this._recordTelemetry("load", cleansedBasename, "used_backup"); this._recordTelemetry("load", cleansedBasename, "used_backup");
} catch (e3) { } catch (e3) {
if (!(e3 instanceof DOMException && e3.name == "NotFoundError")) { if (!(e3 instanceof OS.File.Error && ex.becauseNoSuchFile)) {
Cu.reportError(e3); Cu.reportError(e3);
} }
} }
} }
// In some rare cases it's possible for data to have been added to // In some rare cases it's possible for data to have been added to
// our database between the call to IOUtils.read and when we've been // our database between the call to OS.File.read and when we've been
// notified that there was a problem with it. In that case, leave the // notified that there was a problem with it. In that case, leave the
// synchronously-added data alone. // synchronously-added data alone.
if (this.dataReady) { if (this.dataReady) {
@ -366,13 +373,13 @@ JSONFile.prototype = {
} }
} }
if (this._options.backupFile) { if (this._options.backupTo) {
// Restore the original file from the backup here so fresh writes to empty // Restore the original file from the backup here so fresh writes to empty
// json files don't happen at any time in the future compromising the backup // json files don't happen at any time in the future compromising the backup
// in the process. // in the process.
try { try {
let basename = PathUtils.filename(this.path); let basename = OS.Path.basename(this.path);
let backupFile = new FileUtils.File(this._options.backupFile); let backupFile = new FileUtils.File(this._options.backupTo);
backupFile.copyTo(null, basename); backupFile.copyTo(null, basename);
} catch (e) { } catch (e) {
if ( if (
@ -389,7 +396,7 @@ JSONFile.prototype = {
// user's computer. // user's computer.
// This reads the file and automatically detects the UTF-8 encoding. // This reads the file and automatically detects the UTF-8 encoding.
let inputStream = new FileInputStream( let inputStream = new FileInputStream(
new FileUtils.File(this._options.backupFile), new FileUtils.File(this._options.backupTo),
FileUtils.MODE_RDONLY, FileUtils.MODE_RDONLY,
FileUtils.PERMS_FILE, FileUtils.PERMS_FILE,
0 0
@ -434,27 +441,28 @@ JSONFile.prototype = {
* @rejects JavaScript exception. * @rejects JavaScript exception.
*/ */
async _save() { async _save() {
let json;
try {
json = JSON.stringify(this._data);
} catch (e) {
// If serialization fails, try fallback safe JSON converter.
if (typeof this._data.toJSONSafe == "function") {
json = JSON.stringify(this._data.toJSONSafe());
} else {
throw e;
}
}
// Create or overwrite the file. // Create or overwrite the file.
let bytes = gTextEncoder.encode(json);
if (this._beforeSave) { if (this._beforeSave) {
await Promise.resolve(this._beforeSave()); await Promise.resolve(this._beforeSave());
} }
await OS.File.writeAtomic(
try { this.path,
await IOUtils.writeJSON( bytes,
this.path, Object.assign({ tmpPath: this.path + ".tmp" }, this._options)
this._data, );
Object.assign({ tmpPath: this.path + ".tmp" }, this._options)
);
} catch (ex) {
if (typeof this._data.toJSONSafe == "function") {
// If serialization fails, try fallback safe JSON converter.
await IOUtils.writeUTF8(
this.path,
this._data.toJSONSafe(),
Object.assign({ tmpPath: this.path + ".tmp" }, this._options)
);
}
}
}, },
/** /**