mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-24 03:19:06 +00:00
Bug 1649597, remove OS.File usage from CrashManager.jsm r=barret
Differential Revision: https://phabricator.services.mozilla.com/D98826
This commit is contained in:
parent
8bf24b36c1
commit
04499e3930
@ -7,7 +7,6 @@
|
||||
const myScope = this;
|
||||
|
||||
ChromeUtils.import("resource://gre/modules/Log.jsm", this);
|
||||
ChromeUtils.import("resource://gre/modules/osfile.jsm", this);
|
||||
const { PromiseUtils } = ChromeUtils.import(
|
||||
"resource://gre/modules/PromiseUtils.jsm"
|
||||
);
|
||||
@ -217,7 +216,7 @@ CrashManager.prototype = Object.freeze({
|
||||
|
||||
_lazyGetDir(field, path, leaf) {
|
||||
delete this[field];
|
||||
let value = OS.Path.join(path, leaf);
|
||||
let value = PathUtils.join(path, leaf);
|
||||
Object.defineProperty(this, field, { value });
|
||||
return value;
|
||||
},
|
||||
@ -225,7 +224,7 @@ CrashManager.prototype = Object.freeze({
|
||||
get _crDir() {
|
||||
return this._lazyGetDir(
|
||||
"_crDir",
|
||||
OS.Constants.Path.userApplicationDataDir,
|
||||
Services.dirsvc.get("UAppData", Ci.nsIFile).path,
|
||||
"Crash Reports"
|
||||
);
|
||||
},
|
||||
@ -233,7 +232,7 @@ CrashManager.prototype = Object.freeze({
|
||||
get _storeDir() {
|
||||
return this._lazyGetDir(
|
||||
"_storeDir",
|
||||
OS.Constants.Path.profileDir,
|
||||
Services.dirsvc.get("ProfD", Ci.nsIFile).path,
|
||||
"crashes"
|
||||
);
|
||||
},
|
||||
@ -249,8 +248,8 @@ CrashManager.prototype = Object.freeze({
|
||||
get _eventsDirs() {
|
||||
delete this._eventsDirs;
|
||||
let value = [
|
||||
OS.Path.join(this._crDir, "events"),
|
||||
OS.Path.join(this._storeDir, "events"),
|
||||
PathUtils.join(this._crDir, "events"),
|
||||
PathUtils.join(this._storeDir, "events"),
|
||||
];
|
||||
Object.defineProperty(this, "_eventsDirs", { value });
|
||||
return value;
|
||||
@ -364,7 +363,7 @@ CrashManager.prototype = Object.freeze({
|
||||
);
|
||||
}
|
||||
} catch (ex) {
|
||||
if (ex instanceof OS.File.Error) {
|
||||
if (ex instanceof DOMException) {
|
||||
this._log.warn("I/O error reading " + entry.path, ex);
|
||||
} else {
|
||||
// We should never encounter an exception. This likely represents
|
||||
@ -389,7 +388,7 @@ CrashManager.prototype = Object.freeze({
|
||||
|
||||
for (let path of deletePaths) {
|
||||
try {
|
||||
await OS.File.remove(path);
|
||||
await IOUtils.remove(path);
|
||||
} catch (ex) {
|
||||
this._log.warn("Error removing event file (" + path + ")", ex);
|
||||
}
|
||||
@ -614,7 +613,7 @@ CrashManager.prototype = Object.freeze({
|
||||
// See docs/crash-events.rst for the file format specification.
|
||||
_processEventFile(entry) {
|
||||
return (async () => {
|
||||
let data = await OS.File.read(entry.path);
|
||||
let data = await IOUtils.read(entry.path);
|
||||
let store = await this._getStore();
|
||||
|
||||
let decoder = new TextDecoder();
|
||||
@ -787,39 +786,25 @@ CrashManager.prototype = Object.freeze({
|
||||
*/
|
||||
_getDirectoryEntries(path, re) {
|
||||
return (async function() {
|
||||
try {
|
||||
await OS.File.stat(path);
|
||||
} catch (ex) {
|
||||
if (!(ex instanceof OS.File.Error) || !ex.becauseNoSuchFile) {
|
||||
throw ex;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
let it = new OS.File.DirectoryIterator(path);
|
||||
let children = await IOUtils.getChildren(path);
|
||||
let entries = [];
|
||||
|
||||
try {
|
||||
await it.forEach((entry, index, it) => {
|
||||
if (entry.isDir) {
|
||||
return undefined;
|
||||
}
|
||||
for (const entry of children) {
|
||||
let stat = await IOUtils.stat(entry);
|
||||
if (stat.type == "directory") {
|
||||
continue;
|
||||
}
|
||||
|
||||
let match = re.exec(entry.name);
|
||||
if (!match) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return OS.File.stat(entry.path).then(info => {
|
||||
entries.push({
|
||||
path: entry.path,
|
||||
id: match[1],
|
||||
date: info.lastModificationDate,
|
||||
});
|
||||
});
|
||||
let filename = PathUtils.filename(entry);
|
||||
let match = re.exec(filename);
|
||||
if (!match) {
|
||||
continue;
|
||||
}
|
||||
entries.push({
|
||||
path: entry,
|
||||
id: match[1],
|
||||
date: stat.lastModified,
|
||||
});
|
||||
} finally {
|
||||
it.close();
|
||||
}
|
||||
|
||||
entries.sort((a, b) => {
|
||||
@ -838,9 +823,8 @@ CrashManager.prototype = Object.freeze({
|
||||
return (this._getStoreTask = (async () => {
|
||||
try {
|
||||
if (!this._store) {
|
||||
await OS.File.makeDir(this._storeDir, {
|
||||
ignoreExisting: true,
|
||||
unixMode: OS.Constants.libc.S_IRWXU,
|
||||
await IOUtils.makeDirectory(this._storeDir, {
|
||||
permissions: 0o700,
|
||||
});
|
||||
|
||||
let store = new CrashStore(
|
||||
@ -951,7 +935,7 @@ function CrashStore(storeDir, telemetrySizeKey) {
|
||||
this._storeDir = storeDir;
|
||||
this._telemetrySizeKey = telemetrySizeKey;
|
||||
|
||||
this._storePath = OS.Path.join(storeDir, "store.json.mozlz4");
|
||||
this._storePath = PathUtils.join(storeDir, "store.json.mozlz4");
|
||||
|
||||
// Holds the read data from disk.
|
||||
this._data = null;
|
||||
@ -991,7 +975,7 @@ CrashStore.prototype = Object.freeze({
|
||||
|
||||
try {
|
||||
let decoder = new TextDecoder();
|
||||
let data = await OS.File.read(this._storePath, { compression: "lz4" });
|
||||
let data = await IOUtils.read(this._storePath, { decompress: true });
|
||||
data = JSON.parse(decoder.decode(data));
|
||||
|
||||
if (data.corruptDate) {
|
||||
@ -1070,7 +1054,7 @@ CrashStore.prototype = Object.freeze({
|
||||
}
|
||||
} catch (ex) {
|
||||
// Missing files (first use) are allowed.
|
||||
if (!(ex instanceof OS.File.Error) || !ex.becauseNoSuchFile) {
|
||||
if (!(ex instanceof DOMException) || ex.name != "NotFoundError") {
|
||||
// If we can't load for any reason, mark a corrupt date in the instance
|
||||
// and swallow the error.
|
||||
//
|
||||
@ -1138,9 +1122,9 @@ CrashStore.prototype = Object.freeze({
|
||||
|
||||
let encoder = new TextEncoder();
|
||||
let data = encoder.encode(JSON.stringify(normalized));
|
||||
let size = await OS.File.writeAtomic(this._storePath, data, {
|
||||
let size = await IOUtils.write(this._storePath, data, {
|
||||
tmpPath: this._storePath + ".tmp",
|
||||
compression: "lz4",
|
||||
compress: true,
|
||||
});
|
||||
if (this._telemetrySizeKey) {
|
||||
Services.telemetry.getHistogramById(this._telemetrySizeKey).add(size);
|
||||
|
Loading…
x
Reference in New Issue
Block a user