mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-26 12:20:56 +00:00
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:
parent
a08865ed6c
commit
45468e9761
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user