diff --git a/services/sync/modules/engines.js b/services/sync/modules/engines.js index 5a7837e6a971..d2dc512b543c 100644 --- a/services/sync/modules/engines.js +++ b/services/sync/modules/engines.js @@ -207,7 +207,7 @@ function LegacyTracker(name, engine) { this._ignored = []; this.file = this.name; this._storage = new JSONFile({ - path: Utils.jsonFilePath("changes/" + this.file), + path: Utils.jsonFilePath("changes", this.file), dataPostProcessor: json => this._dataPostProcessor(json), beforeSave: () => this._beforeSave(), }); @@ -767,13 +767,13 @@ function SyncEngine(name, service) { this._log.debug("Engine constructed"); this._toFetchStorage = new JSONFile({ - path: Utils.jsonFilePath("toFetch/" + this.name), + path: Utils.jsonFilePath("toFetch", this.name), dataPostProcessor: json => this._metadataPostProcessor(json), beforeSave: () => this._beforeSaveMetadata(), }); this._previousFailedStorage = new JSONFile({ - path: Utils.jsonFilePath("failed/" + this.name), + path: Utils.jsonFilePath("failed", this.name), dataPostProcessor: json => this._metadataPostProcessor(json), beforeSave: () => this._beforeSaveMetadata(), }); diff --git a/services/sync/modules/util.js b/services/sync/modules/util.js index 0f893dd7a1ea..f0a455d45f6c 100644 --- a/services/sync/modules/util.js +++ b/services/sync/modules/util.js @@ -348,9 +348,14 @@ var Utils = { ).slice(0, SYNC_KEY_DECODED_LENGTH); }, - jsonFilePath(filePath) { - return OS.Path.normalize( - OS.Path.join(OS.Constants.Path.profileDir, "weave", filePath + ".json") + jsonFilePath(...args) { + let [fileName] = args.splice(-1); + + return PathUtils.join( + Services.dirsvc.get("ProfD", Ci.nsIFile).path, + "weave", + ...args, + `${fileName}.json` ); }, @@ -359,7 +364,6 @@ var Utils = { * * @param filePath * JSON file path load from profile. Loaded file will be - * /.json. i.e. Do not specify the ".json" * extension. * @param that * Object to use for logging. @@ -368,10 +372,15 @@ var Utils = { * Promise resolved when the write has been performed. */ async jsonLoad(filePath, that) { - let path = Utils.jsonFilePath(filePath); + let path; + if (Array.isArray(filePath)) { + path = Utils.jsonFilePath(...filePath); + } else { + path = Utils.jsonFilePath(filePath); + } if (that._log && that._log.trace) { - that._log.trace("Loading json from disk: " + filePath); + that._log.trace("Loading json from disk: " + path); } try { diff --git a/services/sync/tests/unit/test_tracker_addChanged.js b/services/sync/tests/unit/test_tracker_addChanged.js index b7aa12b4370b..385ac461bd74 100644 --- a/services/sync/tests/unit/test_tracker_addChanged.js +++ b/services/sync/tests/unit/test_tracker_addChanged.js @@ -52,6 +52,6 @@ add_task(async function test_tracker_persistence() { const changes = await tracker.getChangedIDs(); Assert.equal(5, changes[id]); - let json = await Utils.jsonLoad("changes/tracker", tracker); + let json = await Utils.jsonLoad(["changes", "tracker"], tracker); Assert.equal(5, json[id]); });