mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
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:
parent
df85da1405
commit
f803923b47
@ -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),
|
||||||
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),
|
||||||
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),
|
||||||
dataPostProcessor: json => this._metadataPostProcessor(json),
|
dataPostProcessor: json => this._metadataPostProcessor(json),
|
||||||
beforeSave: () => this._beforeSaveMetadata(),
|
beforeSave: () => this._beforeSaveMetadata(),
|
||||||
});
|
});
|
||||||
|
@ -348,9 +348,14 @@ var Utils = {
|
|||||||
).slice(0, SYNC_KEY_DECODED_LENGTH);
|
).slice(0, SYNC_KEY_DECODED_LENGTH);
|
||||||
},
|
},
|
||||||
|
|
||||||
jsonFilePath(filePath) {
|
jsonFilePath(...args) {
|
||||||
return OS.Path.normalize(
|
let [fileName] = args.splice(-1);
|
||||||
OS.Path.join(OS.Constants.Path.profileDir, "weave", filePath + ".json")
|
|
||||||
|
return PathUtils.join(
|
||||||
|
Services.dirsvc.get("ProfD", Ci.nsIFile).path,
|
||||||
|
"weave",
|
||||||
|
...args,
|
||||||
|
`${fileName}.json`
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -359,7 +364,6 @@ var Utils = {
|
|||||||
*
|
*
|
||||||
* @param filePath
|
* @param filePath
|
||||||
* JSON file path load from profile. Loaded file will be
|
* JSON file path load from profile. Loaded file will be
|
||||||
* <profile>/<filePath>.json. i.e. Do not specify the ".json"
|
|
||||||
* extension.
|
* extension.
|
||||||
* @param that
|
* @param that
|
||||||
* Object to use for logging.
|
* Object to use for logging.
|
||||||
@ -368,10 +372,15 @@ 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;
|
||||||
|
if (Array.isArray(filePath)) {
|
||||||
|
path = Utils.jsonFilePath(...filePath);
|
||||||
|
} else {
|
||||||
|
path = Utils.jsonFilePath(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
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: " + path);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -52,6 +52,6 @@ add_task(async function test_tracker_persistence() {
|
|||||||
const changes = await tracker.getChangedIDs();
|
const changes = await tracker.getChangedIDs();
|
||||||
Assert.equal(5, changes[id]);
|
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]);
|
Assert.equal(5, json[id]);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user