commit 48a81e3b4606b26232f5d8312688c150529cb796
parent c00db272fade0d094fe19716724a8deb4442faa6
Author: Dan Stillman <dstillman@zotero.org>
Date: Sun, 29 Jan 2017 07:50:46 -0500
Fix 412 after choosing local file on file conflict
Diffstat:
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/chrome/content/zotero/xpcom/storage/storageLocal.js b/chrome/content/zotero/xpcom/storage/storageLocal.js
@@ -984,16 +984,20 @@ Zotero.Sync.Storage.Local = {
yield Zotero.DB.executeTransaction(function* () {
for (let i = 0; i < conflicts.length; i++) {
let conflict = conflicts[i];
+ let item = Zotero.Items.getByLibraryAndKey(libraryID, conflict.left.key);
let mtime = io.dataOut[i].dateModified;
// Local
if (mtime == conflict.left.dateModified) {
syncState = this.SYNC_STATE_FORCE_UPLOAD;
+ // When local version is chosen, update stored hash (and mtime) to remote values so
+ // that upload goes through without 412
+ item.attachmentSyncedModificationTime = conflict.right.mtime;
+ item.attachmentSyncedHash = conflict.right.md5;
}
// Remote
else {
syncState = this.SYNC_STATE_FORCE_DOWNLOAD;
}
- let item = Zotero.Items.getByLibraryAndKey(libraryID, conflict.left.key);
item.attachmentSyncState = syncState;
yield item.save({ skipAll: true });
}
diff --git a/test/tests/storageLocalTest.js b/test/tests/storageLocalTest.js
@@ -283,9 +283,11 @@ describe("Zotero.Sync.Storage.Local", function () {
var json1 = item1.toJSON();
var json3 = item3.toJSON();
- // Change remote mtimes
+ // Change remote mtimes and hashes
json1.mtime = new Date().getTime() + 10000;
+ json1.md5 = 'f4ce1167f3a854896c257a0cc1ac387f';
json3.mtime = new Date().getTime() - 10000;
+ json3.md5 = 'fcd080b1c2cad562237823ec27671bbd';
yield Zotero.Sync.Data.Local.saveCacheObjects('item', libraryID, [json1, json3]);
item1.attachmentSyncState = "in_conflict";
@@ -334,7 +336,11 @@ describe("Zotero.Sync.Storage.Local", function () {
yield promise;
assert.equal(item1.attachmentSyncState, Zotero.Sync.Storage.Local.SYNC_STATE_FORCE_UPLOAD);
+ assert.equal(item1.attachmentSyncedModificationTime, json1.mtime);
+ assert.equal(item1.attachmentSyncedHash, json1.md5);
assert.equal(item3.attachmentSyncState, Zotero.Sync.Storage.Local.SYNC_STATE_FORCE_DOWNLOAD);
+ assert.isNull(item3.attachmentSyncedModificationTime);
+ assert.isNull(item3.attachmentSyncedHash);
})
})