diff --git a/chrome/content/zotero/xpcom/storage/storageEngine.js b/chrome/content/zotero/xpcom/storage/storageEngine.js index 179814019..f987ba338 100644 --- a/chrome/content/zotero/xpcom/storage/storageEngine.js +++ b/chrome/content/zotero/xpcom/storage/storageEngine.js @@ -222,7 +222,7 @@ Zotero.Sync.Storage.Engine.prototype.start = Zotero.Promise.coroutine(function* if (p.isFulfilled()) { succeeded++; } - else { + else if (!p.isPending()) { if (this.stopOnError) { let e = p.reason(); Zotero.debug(`File ${type} sync failed for ${this.library.name}`); @@ -237,7 +237,11 @@ Zotero.Sync.Storage.Engine.prototype.start = Zotero.Promise.coroutine(function* changes.updateFromResults(results.filter(p => p.isFulfilled()).map(p => p.value())); - if (type == 'download' && results.every(p => !p.isRejected())) { + if (type == 'download' + // Not stopped + && this.requestsRemaining == 0 + // No errors + && results.every(p => !p.isRejected())) { downloadSuccessful = true; } } diff --git a/test/tests/zfsTest.js b/test/tests/zfsTest.js index f21bd3624..48d6013c4 100644 --- a/test/tests/zfsTest.js +++ b/test/tests/zfsTest.js @@ -164,6 +164,40 @@ describe("Zotero.Sync.Storage.Mode.ZFS", function () { assert.equal(library.storageVersion, library.libraryVersion); }) + it("shouldn't update storageVersion if stopped", function* () { + var { engine, client, caller } = yield setup(); + + var library = Zotero.Libraries.userLibrary; + library.libraryVersion = 5; + yield library.saveTx(); + library.storageDownloadNeeded = true; + + var items = []; + for (let i = 0; i < 5; i++) { + let item = new Zotero.Item("attachment"); + item.attachmentLinkMode = 'imported_file'; + item.attachmentPath = 'storage:test.txt'; + item.attachmentSyncState = "to_download"; + yield item.saveTx(); + items.push(item); + } + + var call = 0; + var stub = sinon.stub(engine.controller, 'downloadFile').callsFake(function () { + call++; + if (call == 1) { + engine.stop(); + } + return new Zotero.Sync.Storage.Result; + }); + + var result = yield engine.start(); + + stub.restore(); + + assert.equal(library.storageVersion, 0); + }); + it("should handle a remotely failing file", function* () { var { engine, client, caller } = yield setup();