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
This commit is contained in:
Barret Rennie 2021-11-17 00:28:59 +00:00
Родитель 72b138b1d8
Коммит e3dee31698
2 изменённых файлов: 11 добавлений и 7 удалений

Просмотреть файл

@ -207,7 +207,7 @@ function LegacyTracker(name, engine) {
this._ignored = []; this._ignored = [];
this.file = this.name; this.file = this.name;
this._storage = new JSONFile({ this._storage = new JSONFile({
path: Utils.jsonFilePath("changes/" + this.file), path: Utils.jsonFilePath("changes", `${this.file}.json`),
dataPostProcessor: json => this._dataPostProcessor(json), dataPostProcessor: json => this._dataPostProcessor(json),
beforeSave: () => this._beforeSave(), beforeSave: () => this._beforeSave(),
}); });
@ -767,13 +767,13 @@ function SyncEngine(name, service) {
this._log.debug("Engine constructed"); this._log.debug("Engine constructed");
this._toFetchStorage = new JSONFile({ this._toFetchStorage = new JSONFile({
path: Utils.jsonFilePath("toFetch/" + this.name), path: Utils.jsonFilePath("toFetch", `${this.name}.json`),
dataPostProcessor: json => this._metadataPostProcessor(json), dataPostProcessor: json => this._metadataPostProcessor(json),
beforeSave: () => this._beforeSaveMetadata(), beforeSave: () => this._beforeSaveMetadata(),
}); });
this._previousFailedStorage = new JSONFile({ this._previousFailedStorage = new JSONFile({
path: Utils.jsonFilePath("failed/" + this.name), path: Utils.jsonFilePath("failed", `${this.name}.json`),
dataPostProcessor: json => this._metadataPostProcessor(json), dataPostProcessor: json => this._metadataPostProcessor(json),
beforeSave: () => this._beforeSaveMetadata(), beforeSave: () => this._beforeSaveMetadata(),
}); });

Просмотреть файл

@ -348,9 +348,13 @@ var Utils = {
).slice(0, SYNC_KEY_DECODED_LENGTH); ).slice(0, SYNC_KEY_DECODED_LENGTH);
}, },
jsonFilePath(filePath) { jsonFilePath(...args) {
return OS.Path.normalize( return PathUtils.normalize(
OS.Path.join(OS.Constants.Path.profileDir, "weave", filePath + ".json") 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. * Promise resolved when the write has been performed.
*/ */
async jsonLoad(filePath, that) { async jsonLoad(filePath, that) {
let path = Utils.jsonFilePath(filePath); let path = Utils.jsonFilePath(`${filePath}.json`);
if (that._log && that._log.trace) { if (that._log && that._log.trace) {
that._log.trace("Loading json from disk: " + filePath); that._log.trace("Loading json from disk: " + filePath);