Fix various file sync issues

- Clear per-library error icon on new sync
- Pass upload errors through to end
- Don't make WebDAV verification error a global failure
- Some other things
This commit is contained in:
Dan Stillman 2013-03-10 01:49:14 -05:00
parent c8386fb40b
commit b7c0427167
3 changed files with 57 additions and 23 deletions

View file

@ -105,22 +105,9 @@ Zotero.Sync.Storage = new function () {
if (Zotero.Sync.Storage.ZFS.includeUserFiles) {
libraryModes[0] = Zotero.Sync.Storage.ZFS;
return;
}
if (Zotero.Sync.Storage.WebDAV.includeUserFiles) {
if (!Zotero.Sync.Storage.WebDAV.verified) {
Zotero.debug("WebDAV file sync is not active");
// Try to verify server now if it hasn't been
return Zotero.Sync.Storage.checkServerPromise(Zotero.Sync.Storage.WebDAV)
.then(function () {
libraryModes[0] = Zotero.Sync.Storage.WebDAV;
});
}
else if (Zotero.Sync.Storage.WebDAV.includeUserFiles) {
libraryModes[0] = Zotero.Sync.Storage.WebDAV;
return;
}
})
.then(function () {
@ -142,15 +129,47 @@ Zotero.Sync.Storage = new function () {
for each(var mode in libraryModes) {
if (modes.indexOf(mode) == -1) {
modes.push(mode);
promises.push(mode.cacheCredentials());
// Try to verify WebDAV server first if it hasn't been
if (mode == Zotero.Sync.Storage.WebDAV
&& !Zotero.Sync.Storage.WebDAV.verified) {
Zotero.debug("WebDAV file sync is not active");
var promise = Zotero.Sync.Storage.checkServerPromise(Zotero.Sync.Storage.WebDAV)
.then(function () {
mode.cacheCredentials();
});
}
else {
var promise = mode.cacheCredentials();
}
promises.push(Q.allResolved([mode, promise]));
}
}
return Q.allResolved(promises)
// Get library last-sync times
.then(function () {
.then(function (cacheCredentialsPromises) {
var promises = [];
// Mark WebDAV verification failure as user library error.
// We ignore credentials-caching errors for ZFS and let the
// later requests fail.
cacheCredentialsPromises.forEach(function (p) {
p = p.valueOf();
let mode = p[0].valueOf();
if (mode == Zotero.Sync.Storage.WebDAV) {
if (p[1].isRejected()) {
promises.push(Q.allResolved(
[0, p[1]]
));
// Skip further syncing of user library
delete libraryModes[0];
}
}
});
for (var libraryID in libraryModes) {
libraryID = parseInt(libraryID);
// Get the last sync time for each library
if (self.downloadOnSync(libraryID)) {
promises.push(Q.allResolved(

View file

@ -43,6 +43,8 @@ Zotero.Sync.Storage.WebDAV = (function () {
* @param {Function} callback Callback f(item, mdate)
*/
function getStorageModificationTime(item) {
var funcName = "Zotero.Sync.Storage.WebDAV.getStorageModificationTime()";
var uri = getItemPropertyURI(item);
return Zotero.HTTP.promise(
@ -51,8 +53,6 @@ Zotero.Sync.Storage.WebDAV = (function () {
.then(function (req) {
checkResponse(req);
var funcName = "Zotero.Sync.Storage.WebDAV.getStorageModificationTime()";
// mod_speling can return 300s for 404s with base name matches
if (req.status == 404 || req.status == 300) {
return false;
@ -113,7 +113,6 @@ Zotero.Sync.Storage.WebDAV = (function () {
})
.catch(function (e) {
if (e instanceof Zotero.HTTP.UnexpectedStatusException) {
Zotero.debug(req.responseText);
throw new Error("Unexpected status code " + e.status + " in " + funcName);
}
throw e;
@ -266,7 +265,9 @@ Zotero.Sync.Storage.WebDAV = (function () {
},
onStop: function (httpRequest, status, response, data) {
deferred.resolve(
onUploadComplete(httpRequest, status, response, data)
Q.fcall(function () {
return onUploadComplete(httpRequest, status, response, data);
})
);
},
onCancel: function (httpRequest, status, data) {
@ -945,7 +946,11 @@ Zotero.Sync.Storage.WebDAV = (function () {
Zotero.Sync.Storage.createUploadFile(
request,
function (data) {
deferred.resolve(processUploadFile(data));
deferred.resolve(
Q.fcall(function () {
return processUploadFile(data);
})
);
}
);
return deferred.promise;

View file

@ -733,6 +733,10 @@ Zotero.Sync.Runner = new function () {
* library-specific sync error icons across all windows
*/
this.setErrors = function (errors) {
if (!errors) {
errors = [];
}
errors = [this.parseSyncError(e) for each(e in errors)];
_errorsByLibrary = {};
@ -898,8 +902,9 @@ Zotero.Sync.Runner = new function () {
}
}
if (!parsed.message) {
// TODO: include file name and line?
parsed.message = e.message ? e.message : e;
parsed.fileName = e.fileName;
parsed.lineNumber = e.lineNumber;
}
parsed.frontWindowOnly = !!(e && e.data && e.data.frontWindowOnly);
@ -958,7 +963,11 @@ Zotero.Sync.Runner = new function () {
e = this.parseSyncError(e);
var desc = doc.createElement('description');
desc.textContent = e.message;
var msg = e.message;
/*if (e.fileName) {
msg += '\n\nFile: ' + e.fileName + '\nLine: ' + e.lineNumber;
}*/
desc.textContent = msg;
panelContent.appendChild(desc);
// If not an error and there's no explicit button text, don't show
@ -1356,6 +1365,7 @@ Zotero.Sync.Server = new function () {
var self = this;
Zotero.Sync.Runner.setErrors();
Zotero.Sync.Runner.setSyncIcon('animate');
if (!_sessionID) {