From e3dee316989b1997096c07a27fdf4874c8e4dfdf Mon Sep 17 00:00:00 2001 From: Barret Rennie Date: Wed, 17 Nov 2021 00:28:59 +0000 Subject: [PATCH] Bug 1736175 - Use PathUtils for generating paths in sync engines r=markh In bug 1649604, JSONFile was rewritten to use IOUtils and PathUtils for file IO and path management. This means that all path operations go through nsIFile methods. However, sync engines were generating paths that always contained a forward slash. If that file is a UNC path (i.e., if your profile is located on a network drive), all IOUtils and PathUtils operations on that drive will fail due to nsLocalFile::InitWithPath on Windows rejecting paths contaiing a forward slash with NS_ERROR_FILE_UNRECOGNIZED_PATH. This only occurred with UNC paths because OS.Path.normalize would normalize forward slashes to backslashes, except when the path is a UNC path. This meant that you could not use FxA sync with a profile on a network drive. Updating these engines to use PathUtils to join the paths instead of hardcoding forward slashes fixes this issue and allows sync to work with profiles on network drives. Differential Revision: https://phabricator.services.mozilla.com/D131166 --- services/sync/modules/engines.js | 6 +++--- services/sync/modules/util.js | 12 ++++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/services/sync/modules/engines.js b/services/sync/modules/engines.js index 5a7837e6a971..f536e5cbdc61 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}.json`), 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}.json`), dataPostProcessor: json => this._metadataPostProcessor(json), beforeSave: () => this._beforeSaveMetadata(), }); this._previousFailedStorage = new JSONFile({ - path: Utils.jsonFilePath("failed/" + this.name), + path: Utils.jsonFilePath("failed", `${this.name}.json`), dataPostProcessor: json => this._metadataPostProcessor(json), beforeSave: () => this._beforeSaveMetadata(), }); diff --git a/services/sync/modules/util.js b/services/sync/modules/util.js index 0f893dd7a1ea..e3f915eb059c 100644 --- a/services/sync/modules/util.js +++ b/services/sync/modules/util.js @@ -348,9 +348,13 @@ 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) { + return PathUtils.normalize( + PathUtils.join( + Services.dirsvc.get("ProfD", Ci.nsIFile).path, + "weave", + ...args + ) ); }, @@ -368,7 +372,7 @@ var Utils = { * Promise resolved when the write has been performed. */ async jsonLoad(filePath, that) { - let path = Utils.jsonFilePath(filePath); + let path = Utils.jsonFilePath(`${filePath}.json`); if (that._log && that._log.trace) { that._log.trace("Loading json from disk: " + filePath);