Commit b6c71fb0 authored by Beth Rennie's avatar Beth Rennie
Browse files

Bug 1772940 - Port osfile.jsm usage to IOUtils in toolkit/components/xulstore/ r=Gijs

parent 6308d40d
Loading
Loading
Loading
Loading
+1 −9
Original line number Diff line number Diff line
@@ -12,10 +12,6 @@ const WRITE_DELAY_MS = (debugMode ? 3 : 30) * 1000;
const XULSTORE_CID = Components.ID("{6f46b6f4-c8b1-4bd4-a4fa-9ebbed0753ea}");
const STOREDB_FILENAME = "xulstore.json";

const lazy = {};

ChromeUtils.defineModuleGetter(lazy, "OS", "resource://gre/modules/osfile.jsm");

function XULStore() {
  if (!Services.appinfo.inSafeMode) {
    this.load();
@@ -104,11 +100,7 @@ XULStore.prototype = {
    this.log("Writing to xulstore.json");

    try {
      let data = JSON.stringify(this._data);
      let encoder = new TextEncoder();

      data = encoder.encode(data);
      await lazy.OS.File.writeAtomic(this._storeFile.path, data, {
      await IOUtils.writeJSON(this._storeFile.path, this._data, {
        tmpPath: this._storeFile.path + ".tmp",
      });
    } catch (e) {
+2 −3
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@
const { AppConstants } = ChromeUtils.import(
  "resource://gre/modules/AppConstants.jsm"
);
const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm");

function run_test() {
  do_get_profile();
@@ -15,7 +14,7 @@ add_task(
    skip_if: () => !AppConstants.MOZ_NEW_XULSTORE,
  },
  async function test_create_old_datastore() {
    const path = OS.Path.join(OS.Constants.Path.profileDir, "xulstore.json");
    const path = PathUtils.join(PathUtils.profileDir, "xulstore.json");

    const xulstoreJSON = {
      doc1: {
@@ -37,7 +36,7 @@ add_task(
      doc3: {},
    };

    await OS.File.writeAtomic(path, JSON.stringify(xulstoreJSON));
    await IOUtils.writeJSON(path, xulstoreJSON);
  }
);

+2 −3
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@
const { AppConstants } = ChromeUtils.import(
  "resource://gre/modules/AppConstants.jsm"
);
const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm");

function run_test() {
  do_get_profile();
@@ -15,7 +14,7 @@ add_task(
    skip_if: () => !AppConstants.MOZ_NEW_XULSTORE,
  },
  async function test_create_old_datastore() {
    const path = OS.Path.join(OS.Constants.Path.profileDir, "xulstore.json");
    const path = PathUtils.join(PathUtils.profileDir, "xulstore.json");

    // Valid JSON, but invalid data: attr1's value is a number, not a string.
    const xulstoreJSON = {
@@ -31,7 +30,7 @@ add_task(
      },
    };

    await OS.File.writeAtomic(path, JSON.stringify(xulstoreJSON));
    await IOUtils.writeJSON(path, xulstoreJSON);
  }
);

+2 −3
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@
const { AppConstants } = ChromeUtils.import(
  "resource://gre/modules/AppConstants.jsm"
);
const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm");

function run_test() {
  do_get_profile();
@@ -15,12 +14,12 @@ add_task(
    skip_if: () => !AppConstants.MOZ_NEW_XULSTORE,
  },
  async function test_create_old_datastore() {
    const path = OS.Path.join(OS.Constants.Path.profileDir, "xulstore.json");
    const path = PathUtils.join(PathUtils.profileDir, "xulstore.json");

    // Invalid JSON: it's missing the final closing brace.
    const xulstoreJSON = '{ doc: { id: { attr: "value" } }';

    await OS.File.writeAtomic(path, xulstoreJSON);
    await IOUtils.writeUTF8(path, xulstoreJSON);
  }
);

+1 −2
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@
const { AppConstants } = ChromeUtils.import(
  "resource://gre/modules/AppConstants.jsm"
);
const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm");
const { FileUtils } = ChromeUtils.import(
  "resource://gre/modules/FileUtils.jsm"
);
@@ -27,7 +26,7 @@ add_task(
    // Register an observer before the XULStore service registers its observer,
    // so we can observe the profile-after-change notification first and create
    // an old store for it to migrate.  We need to write synchronously to avoid
    // racing XULStore, so we use FileUtils instead of OS.File.
    // racing XULStore, so we use FileUtils instead of IOUtils.
    Services.obs.addObserver(
      {
        observe() {