Don't update storage version if file sync is stopped

Otherwise subsequent syncs won't download the remaining files until
there's a remote storage change.
This commit is contained in:
Dan Stillman 2017-08-11 20:29:32 +02:00
parent 9069559050
commit 2770860968
2 changed files with 40 additions and 2 deletions

View file

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

View file

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