diff --git a/services/sync/modules/constants.js b/services/sync/modules/constants.js index f3cb556bc516..162cb9ccfceb 100644 --- a/services/sync/modules/constants.js +++ b/services/sync/modules/constants.js @@ -34,7 +34,7 @@ * * ***** END LICENSE BLOCK ***** */ -const EXPORTED_SYMBOLS = ["WEAVE_VERSION", "STORAGE_VERSION", +const EXPORTED_SYMBOLS = ["WEAVE_VERSION", "COMPATIBLE_VERSION", 'PREFS_BRANCH', 'MODE_RDONLY', 'MODE_WRONLY', 'MODE_CREATE', 'MODE_APPEND', 'MODE_TRUNCATE', @@ -59,7 +59,7 @@ const WEAVE_VERSION = "@weave_version@"; // last client version's server storage this version supports // e.g. if set to the current version, this client will wipe the server // data stored by any older client -const STORAGE_VERSION = "@storage_version@"; +const COMPATIBLE_VERSION = "@compatible_version@"; const PREFS_BRANCH = "extensions.weave."; diff --git a/services/sync/modules/service.js b/services/sync/modules/service.js index b6e98f8336fb..9c8bf2b205df 100644 --- a/services/sync/modules/service.js +++ b/services/sync/modules/service.js @@ -682,11 +682,11 @@ WeaveSvc.prototype = { let remoteVersion = (meta && meta.payload.storageVersion)? meta.payload.storageVersion : ""; - this._log.debug("Local storage version is " + STORAGE_VERSION); - this._log.debug("Remote storage version is " + remoteVersion); + this._log.debug(["Weave Version:", WEAVE_VERSION, "Compatible:", + COMPATIBLE_VERSION, "Remote:", remoteVersion].join(" ")); if (!meta || !meta.payload.storageVersion || !meta.payload.syncID || - Svc.Version.compare(STORAGE_VERSION, remoteVersion) > 0) { + Svc.Version.compare(COMPATIBLE_VERSION, remoteVersion) > 0) { // abort the server wipe if the GET status was anything other than 404 or 200 let status = Records.lastResource.lastChannel.responseStatus; @@ -701,8 +701,8 @@ WeaveSvc.prototype = { this._log.info("No metadata record, server wipe needed"); if (meta && !meta.payload.syncID) this._log.warn("No sync id, server wipe needed"); - if (Svc.Version.compare(STORAGE_VERSION, remoteVersion) > 0) - this._log.info("Server storage version no longer supported, server wipe needed"); + if (Svc.Version.compare(COMPATIBLE_VERSION, remoteVersion) > 0) + this._log.info("Server data is older than what Weave supports, server wipe needed"); if (!this._keyGenEnabled) { this._log.info("...and key generation is disabled. Not wiping. " + @@ -719,9 +719,9 @@ WeaveSvc.prototype = { "consistency."); else // 200 this._log.info("Server data wiped to ensure consistency after client " + - "upgrade (" + remoteVersion + " -> " + STORAGE_VERSION + ")"); + "upgrade (" + remoteVersion + " -> " + WEAVE_VERSION + ")"); - } else if (Svc.Version.compare(remoteVersion, STORAGE_VERSION) > 0) { + } else if (Svc.Version.compare(remoteVersion, WEAVE_VERSION) > 0) { this._setSyncFailure(VERSION_OUT_OF_DATE); this._log.warn("Server data is of a newer Weave version, this client " + "needs to be upgraded. Aborting sync."); @@ -734,7 +734,11 @@ WeaveSvc.prototype = { this._log.info("Reset client because of syncID mismatch."); Clients.syncID = meta.payload.syncID; this._log.info("Reset the client after a server/client sync ID mismatch"); + this._updateRemoteVersion(meta); } + // We didn't wipe the server and we're not out of date, so update remote + else + this._updateRemoteVersion(meta); let needKeys = true; let pubkey = PubKeys.getDefaultKey(); @@ -1001,9 +1005,17 @@ WeaveSvc.prototype = { this._log.debug("Uploading new metadata record"); meta = new WBORecord(this.clusterURL + this.username + "/meta/global"); - this._log.debug("Setting meta payload storage version to " + STORAGE_VERSION); - meta.payload.storageVersion = STORAGE_VERSION; meta.payload.syncID = Clients.syncID; + this._updateRemoteVersion(meta); + }, + + _updateRemoteVersion: function WeaveSvc__updateRemoteVersion(meta) { + // Don't update if the remote version is already newer + if (Svc.Version.compare(meta.payload.storageVersion, WEAVE_VERSION) >= 0) + return; + + this._log.debug("Setting meta payload storage version to " + WEAVE_VERSION); + meta.payload.storageVersion = WEAVE_VERSION; let res = new Resource(meta.uri); res.put(meta.serialize()); },