Bug 1772180 - Port osfile.jsm usage to IOUtils in browser/modules/ r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D153697
This commit is contained in:
Barret Rennie 2022-11-21 23:53:15 +00:00
parent a08865ed6c
commit 45468e9761

View File

@ -14,7 +14,6 @@ const { FileUtils } = ChromeUtils.importESModule(
const { makeFakeAppDir } = ChromeUtils.importESModule(
"resource://testing-common/AppData.sys.mjs"
);
const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm");
const DAY = 24 * 60 * 60 * 1000; // milliseconds
const SERVER_URL =
@ -82,28 +81,26 @@ function createPendingCrashReports(howMany, accessDate) {
* extension. This is usually a UUID.
* @param extension (string)
* The file extension for the created file.
* @param accessDate (Date)
* The date to set lastAccessed to.
* @param accessDate (Date, optional)
* The date to set lastAccessed to, if anything.
* @param contents (string, optional)
* Set this to whatever the file needs to contain, if anything.
* @returns Promise
*/
let createFile = (fileName, extension, lastAccessedDate, contents) => {
let createFile = async (fileName, extension, lastAccessedDate, contents) => {
let file = dir.clone();
file.append(fileName + "." + extension);
file.create(Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);
let promises = [OS.File.setDates(file.path, lastAccessedDate)];
if (contents) {
let encoder = new TextEncoder();
let array = encoder.encode(contents);
promises.push(
OS.File.writeAtomic(file.path, array, {
tmpPath: file.path + ".tmp",
})
);
await IOUtils.writeUTF8(file.path, contents, {
tmpPath: file.path + ".tmp",
});
}
if (lastAccessedDate) {
await IOUtils.setAccessTime(file.path, lastAccessedDate.valueOf());
}
return Promise.all(promises);
};
let uuidGenerator = Services.uuid;