diff --git a/chrome/content/zotero/xpcom/storage/storageLocal.js b/chrome/content/zotero/xpcom/storage/storageLocal.js index 354a2c6a7..f74d0f74a 100644 --- a/chrome/content/zotero/xpcom/storage/storageLocal.js +++ b/chrome/content/zotero/xpcom/storage/storageLocal.js @@ -577,13 +577,10 @@ Zotero.Sync.Storage.Local = { // Set the file mtime to the time from the server yield OS.File.setDates(path, null, new Date(parseInt(mtime))); - item.attachmentSyncState = this.SYNC_STATE_IN_SYNC; item.attachmentSyncedModificationTime = mtime; item.attachmentSyncedHash = md5; - yield item.saveTx({ - skipDateModifiedUpdate: true, - skipSelect: true - }); + item.attachmentSyncState = "in_sync"; + yield item.saveTx({ skipAll: true }); return new Zotero.Sync.Storage.Result({ localChanges: true diff --git a/chrome/content/zotero/xpcom/storage/streamListener.js b/chrome/content/zotero/xpcom/storage/streamListener.js index 136a8f895..8b1323e24 100644 --- a/chrome/content/zotero/xpcom/storage/streamListener.js +++ b/chrome/content/zotero/xpcom/storage/streamListener.js @@ -156,6 +156,8 @@ Zotero.Sync.Storage.StreamListener.prototype = { if (!result) { oldChannel.cancel(Components.results.NS_BINDING_ABORTED); newChannel.cancel(Components.results.NS_BINDING_ABORTED); + Zotero.debug("Cancelling redirect"); + // TODO: Prevent onStateChange error return false; } } diff --git a/chrome/content/zotero/xpcom/storage/zfs.js b/chrome/content/zotero/xpcom/storage/zfs.js index e8f2b4bfa..df5a6989f 100644 --- a/chrome/content/zotero/xpcom/storage/zfs.js +++ b/chrome/content/zotero/xpcom/storage/zfs.js @@ -99,7 +99,7 @@ Zotero.Sync.Storage.Mode.ZFS.prototype = { var header; try { header = "Zotero-File-Modification-Time"; - requestData.mtime = oldChannel.getResponseHeader(header); + requestData.mtime = parseInt(oldChannel.getResponseHeader(header)); header = "Zotero-File-MD5"; requestData.md5 = oldChannel.getResponseHeader(header); header = "Zotero-File-Compressed"; @@ -131,6 +131,7 @@ Zotero.Sync.Storage.Mode.ZFS.prototype = { } // Update local metadata and stop request, skipping file download + yield OS.File.setDates(path, null, new Date(requestData.mtime)); item.attachmentSyncedModificationTime = requestData.mtime; if (updateHash) { item.attachmentSyncedHash = requestData.md5; @@ -138,6 +139,10 @@ Zotero.Sync.Storage.Mode.ZFS.prototype = { item.attachmentSyncState = "in_sync"; yield item.saveTx({ skipAll: true }); + deferred.resolve(new Zotero.Sync.Storage.Result({ + localChanges: true + })); + return false; }), onProgress: function (a, b, c) { diff --git a/test/tests/zfsTest.js b/test/tests/zfsTest.js index 7c26982ad..6178bd0bb 100644 --- a/test/tests/zfsTest.js +++ b/test/tests/zfsTest.js @@ -561,6 +561,60 @@ describe("Zotero.Sync.Storage.Mode.ZFS", function () { assert.equal(item2.version, 15); }) + it("should update local info for remotely updated file that matches local file", function* () { + var { engine, client, caller } = yield setup(); + + var library = Zotero.Libraries.userLibrary; + library.libraryVersion = 5; + yield library.saveTx(); + library.storageDownloadNeeded = true; + + var file = getTestDataDirectory(); + file.append('test.txt'); + var item = yield Zotero.Attachments.importFromFile({ file }); + item.version = 5; + item.attachmentSyncState = "to_download"; + yield item.saveTx(); + var path = yield item.getFilePathAsync(); + yield OS.File.setDates(path, null, new Date() - 100000); + + var json = item.toJSON(); + yield Zotero.Sync.Data.Local.saveCacheObject('item', item.libraryID, json); + + var mtime = (Math.floor(new Date().getTime() / 1000) * 1000) + ""; + var md5 = Zotero.Utilities.Internal.md5(file) + + var s3Path = `pretend-s3/${item.key}`; + this.httpd.registerPathHandler( + `/users/1/items/${item.key}/file`, + { + handle: function (request, response) { + if (!request.hasHeader('Zotero-API-Key')) { + response.setStatusLine(null, 403, "Forbidden"); + return; + } + var key = request.getHeader('Zotero-API-Key'); + if (key != apiKey) { + response.setStatusLine(null, 403, "Invalid key"); + return; + } + response.setStatusLine(null, 302, "Found"); + response.setHeader("Zotero-File-Modification-Time", mtime, false); + response.setHeader("Zotero-File-MD5", md5, false); + response.setHeader("Zotero-File-Compressed", "No", false); + response.setHeader("Location", baseURL + s3Path, false); + } + } + ); + var result = yield engine.start(); + + assert.equal(item.attachmentSyncedModificationTime, mtime); + yield assert.eventually.equal(item.attachmentModificationTime, mtime); + assert.isTrue(result.localChanges); + assert.isFalse(result.remoteChanges); + assert.isFalse(result.syncRequired); + }) + it("should update local info for file that already exists on the server", function* () { var { engine, client, caller } = yield setup();