From de1d1acb26e7755631e19263b012b57878a228b7 Mon Sep 17 00:00:00 2001 From: Dan Mills Date: Wed, 11 Jun 2008 11:12:04 +0900 Subject: [PATCH] Various changes: Engine/RemoteStore: * Move code to make the engine remote directory into RemoteStore. * Fix initSession call in Engine to properly use callback / call yield. * Do not check '_getServerData' return status in _sync, we will use exceptions from RemoteStore instead. * Move code to push a new delta into RemoteStore (appendDelta()). Currently comments out code that forces a re-upload in cases where the server (engine) format version was different. We may add this back later into RemoteStore (?). * Note that this patch also removes the 'this._encryptionChanged' conditional, which I believe is currently useless (we never set it). Service: * When wiping the server (due to a server version mismatch), skip .htaccess files, since they are usually not user-modifiable. --- services/sync/modules/engines.js | 58 +++++++++++--------------------- services/sync/modules/remote.js | 37 +++++++++++++++++++- services/sync/modules/service.js | 6 ++-- 3 files changed, 59 insertions(+), 42 deletions(-) diff --git a/services/sync/modules/engines.js b/services/sync/modules/engines.js index 6d5381cec16..fb7f2e90c5e 100644 --- a/services/sync/modules/engines.js +++ b/services/sync/modules/engines.js @@ -270,29 +270,17 @@ Engine.prototype = { this._log.info("Beginning sync"); - // Before we get started, make sure we have a remote directory to play in - DAV.MKCOL(this.serverPrefix, self.cb); - let ret = yield; - if (!ret) - throw "Could not create remote folder"; + this._remote.initSession(self.cb); + yield; - this._remote.initSession(); + this._log.info("Local snapshot version: " + this._snapshot.version); + this._log.info("Server maxVersion: " + this._remote.status.data.maxVersion); + this._log.debug("Server snapVersion: " + this._remote.status.data.snapVersion); // 1) Fetch server deltas this._getServerData.async(this, self.cb); let server = yield; - this._log.info("Local snapshot version: " + this._snapshot.version); - this._log.info("Server status: " + server.status); - this._log.info("Server maxVersion: " + server.maxVersion); - this._log.info("Server snapVersion: " + server.snapVersion); - - if (server.status != 0) { - this._log.fatal("Sync error: could not get server status, " + - "or initial upload failed. Aborting sync."); - return; - } - // 2) Generate local deltas from snapshot -> current client status let localJson = new SnapshotStore(); @@ -399,39 +387,31 @@ Engine.prototype = { if (serverDelta.length) { this._log.info("Uploading changes to server"); - this._snapshot.data = newSnapshot; this._snapshot.version = ++server.maxVersion; - server.deltas.push(serverDelta); - - if (server.formatVersion != ENGINE_STORAGE_FORMAT_VERSION || - this._encryptionChanged) { + /* + if (server.formatVersion != ENGINE_STORAGE_FORMAT_VERSION) { this._fullUpload.async(this, self.cb); let status = yield; if (!status) this._log.error("Could not upload files to server"); // eep? + */ - } else { - this._remote.deltas.put(self.cb, server.deltas); - yield; + this._remote.appendDelta(self.cb, serverDelta); + yield; - let c = 0; - for (GUID in this._snapshot.data) - c++; + let c = 0; + for (GUID in this._snapshot.data) + c++; - this._remote.status.put(self.cb, - {GUID: this._snapshot.GUID, - formatVersion: ENGINE_STORAGE_FORMAT_VERSION, - snapVersion: server.snapVersion, - maxVersion: this._snapshot.version, - snapEncryption: server.snapEncryption, - deltasEncryption: Crypto.defaultAlgorithm, - itemCount: c}); + this._remote.status.data.maxVersion = this._snapshot.version; + this._remote.status.data.snapEncryption = Crypto.defaultAlgorithm; + this._remote.status.data.itemCount = c; + this._remote.status.put(self.cb, this._remote.status.data); - this._log.info("Successfully updated deltas and status on server"); - this._snapshot.save(); - } + this._log.info("Successfully updated deltas and status on server"); + this._snapshot.save(); } this._log.info("Sync complete"); diff --git a/services/sync/modules/remote.js b/services/sync/modules/remote.js index 0caf0d58e99..8ec83bc36b6 100644 --- a/services/sync/modules/remote.js +++ b/services/sync/modules/remote.js @@ -369,6 +369,7 @@ Deltas.prototype = { function RemoteStore(serverPrefix, cryptoId) { this._prefix = serverPrefix; this._cryptoId = cryptoId; + this._log = Log4Moz.Service.getLogger("Service.RemoteStore"); } RemoteStore.prototype = { get serverPrefix() this._prefix, @@ -410,7 +411,7 @@ RemoteStore.prototype = { return deltas; }, - initSession: function RStore_initSession(serverPrefix, cryptoId) { + _initSession: function RStore__initSession(serverPrefix, cryptoId) { let self = yield; if (serverPrefix) @@ -425,11 +426,21 @@ RemoteStore.prototype = { this.snapshot.data = null; this.deltas.data = null; + DAV.MKCOL(this.serverPrefix, self.cb); + let ret = yield; + if (!ret) + throw "Could not create remote folder"; + + this._log.debug("Downloading status file"); this.status.get(self.cb); yield; + this._log.debug("Downloading status file... done"); this._inited = true; }, + initSession: function RStore_initSession(onComplete, serverPrefix, cryptoId) { + this._initSession.async(this, onComplete, serverPrefix, cryptoId); + }, closeSession: function RStore_closeSession() { this._inited = false; @@ -437,5 +448,29 @@ RemoteStore.prototype = { this.keys.data = null; this.snapshot.data = null; this.deltas.data = null; + }, + + _appendDelta: function RStore__appendDelta(delta) { + let self = yield; + if (this.deltas.data == null) { + this.deltas.get(self.cb); + yield; + if (this.deltas.data == null) + this.deltas.data = []; + } + this.deltas.data.push(delta); + this.deltas.put(self.cb, this.deltas.data); + yield; + }, + appendDelta: function RStore_appendDelta(onComplete, delta) { + this._appendDeltas.async(this, onComplete, delta); + }, + + _getUpdates: function RStore__getUpdates(lastSyncSnap) { + let self = yield; + + }, + getUpdates: function RStore_getUpdates(onComplete, lastSyncSnap) { + this._getUpdates.async(this, onComplete); } }; diff --git a/services/sync/modules/service.js b/services/sync/modules/service.js index d8d68bb26fb..83fcf2a9191 100644 --- a/services/sync/modules/service.js +++ b/services/sync/modules/service.js @@ -479,6 +479,8 @@ WeaveSvc.prototype = { let names = yield; for (let i = 0; i < names.length; i++) { + if (names[i].match(/\.htaccess$/)) + continue; DAV.DELETE(names[i], self.cb); let resp = yield; this._log.debug(resp.status); @@ -573,7 +575,7 @@ WeaveSvc.prototype = { to indicate whether sharing succeeded or failed. Implementation, as well as the interpretation of what 'guid' means, is left up to the engine for the specific dataType. */ - + // TODO who is listening for the share-bookmarks message? let messageName = "share-" + dataType; // so for instance, if dataType is "bookmarks" then a message @@ -585,7 +587,7 @@ WeaveSvc.prototype = { guid, username)).async(this, onComplete); }, - _shareBookmarks: function WeaveSync__shareBookmarks(dataType, + _shareBookmarks: function WeaveSync__shareBookmarks(dataType, guid, username) { let self = yield;