Bug 1747463 - Remove FileUtils.getFile from dom/ r=asuth

While here I also migreated the few usages of OSFile over to IOUtils.

Differential Revision: https://phabricator.services.mozilla.com/D134900
This commit is contained in:
Barret Rennie 2022-01-22 01:17:26 +00:00
parent ce0cb47934
commit 471d308b61

View File

@ -21,7 +21,6 @@ ChromeUtils.defineModuleGetter(
"KeyValueService", "KeyValueService",
"resource://gre/modules/kvstore.jsm" "resource://gre/modules/kvstore.jsm"
); );
ChromeUtils.defineModuleGetter(this, "OS", "resource://gre/modules/osfile.jsm");
ChromeUtils.defineModuleGetter( ChromeUtils.defineModuleGetter(
this, this,
"Services", "Services",
@ -111,11 +110,12 @@ var NotificationDB = {
}, },
async maybeMigrateData() { async maybeMigrateData() {
// We avoid using OS.File until we know we're going to migrate data const oldStore = PathUtils.join(
// to avoid the performance cost of loading that module. Services.dirsvc.get("ProfD", Ci.nsIFile).path,
const oldStore = FileUtils.getFile("ProfD", ["notificationstore.json"]); "notificationstore.json"
);
if (!oldStore.exists()) { if (!(await IOUtils.exists(oldStore))) {
if (DEBUG) { if (DEBUG) {
debug("Old store doesn't exist; not migrating data."); debug("Old store doesn't exist; not migrating data.");
} }
@ -124,7 +124,7 @@ var NotificationDB = {
let data; let data;
try { try {
data = await OS.File.read(oldStore.path, { encoding: "utf-8" }); data = await IOUtils.readUTF8(oldStore);
} catch (ex) { } catch (ex) {
// If read failed, we assume we have no notifications to migrate. // If read failed, we assume we have no notifications to migrate.
if (DEBUG) { if (DEBUG) {
@ -133,7 +133,7 @@ var NotificationDB = {
return; return;
} finally { } finally {
// Finally, delete the old file so we don't try to migrate it again. // Finally, delete the old file so we don't try to migrate it again.
await OS.File.remove(oldStore.path); await IOUtils.remove(oldStore);
} }
if (data.length > 0) { if (data.length > 0) {