This commit is contained in:
Myk Melez 2008-06-11 10:41:57 -07:00
commit 932871d1bd
3 changed files with 59 additions and 42 deletions

View File

@ -272,29 +272,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();
@ -401,39 +389,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

@ -501,6 +501,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);
@ -669,7 +671,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
@ -681,7 +683,7 @@ WeaveSvc.prototype = {
guid,
username)).async(this, onComplete);
},
_shareBookmarks: function WeaveSync__shareBookmarks(dataType,
_shareBookmarks: function WeaveSync__shareBookmarks(dataType,
guid,
username) {
let self = yield;