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.
This commit is contained in:
Dan Mills 2008-06-11 11:12:04 +09:00
parent 9c1413e024
commit de1d1acb26
3 changed files with 59 additions and 42 deletions

View File

@ -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");

View File

@ -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);
}
};

View File

@ -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);