commit 69430d74b2f74c87d04df4b55b78138a02326401
parent 747c11c917fa96ecf5c30d63e8276600bdc4cce5
Author: Dan Stillman <dstillman@zotero.org>
Date: Tue, 13 Dec 2016 01:25:56 -0500
Maybe fix race condition when updating translators manually at startup
If you got the timing just right, you could wipe out all your
translators (though standard ones would be reinstalled on restart).
Hopefully that's fixed?
Diffstat:
1 file changed, 16 insertions(+), 18 deletions(-)
diff --git a/chrome/content/zotero/xpcom/schema.js b/chrome/content/zotero/xpcom/schema.js
@@ -967,10 +967,10 @@ Zotero.Schema = new function(){
/**
* Send XMLHTTP request for updated translators and styles to the central repository
*
- * @param {Boolean} force Force a repository query regardless of how
- * long it's been since the last check
+ * @param {Integer} [force=0] - If non-zero, force a repository query regardless of how long it's
+ * been since the last check. 1 means manual update, 2 means forced update after upgrade.
*/
- this.updateFromRepository = Zotero.Promise.coroutine(function* (force) {
+ this.updateFromRepository = Zotero.Promise.coroutine(function* (force = 0) {
if (!force) {
if (_remoteUpdateInProgress) {
Zotero.debug("A remote update is already in progress -- not checking repository");
@@ -1025,13 +1025,11 @@ Zotero.Schema = new function(){
_remoteUpdateInProgress = true;
- if (force) {
- if (force == 2) {
- url += '&m=2';
- }
- else {
- url += '&m=1';
- }
+ if (force == 2) {
+ url += '&m=2';
+ }
+ else if (force) {
+ url += '&m=1';
}
// Send list of installed styles
@@ -1054,7 +1052,7 @@ Zotero.Schema = new function(){
try {
var xmlhttp = yield Zotero.HTTP.request("POST", url, { body: body });
- return _updateFromRepositoryCallback(xmlhttp, !!force);
+ return _updateFromRepositoryCallback(xmlhttp, force);
}
catch (e) {
if (e instanceof Zotero.HTTP.UnexpectedStatusException
@@ -1493,7 +1491,7 @@ Zotero.Schema = new function(){
*
* @return {Promise:Boolean} A promise for whether the update suceeded
**/
- function _updateFromRepositoryCallback(xmlhttp, manual) {
+ function _updateFromRepositoryCallback(xmlhttp, force) {
if (!xmlhttp.responseXML){
try {
if (xmlhttp.status>1000){
@@ -1509,7 +1507,7 @@ Zotero.Schema = new function(){
Zotero.debug('Repository cannot be contacted');
}
- if (!manual){
+ if (!force) {
_setRepositoryTimer(ZOTERO_CONFIG['REPOSITORY_RETRY_INTERVAL']);
}
@@ -1642,7 +1640,7 @@ Zotero.Schema = new function(){
})
.then(function () {
Zotero.debug('All translators and styles are up-to-date');
- if (!manual) {
+ if (!force) {
_setRepositoryTimer(ZOTERO_CONFIG['REPOSITORY_CHECK_INTERVAL']);
}
@@ -1664,12 +1662,12 @@ Zotero.Schema = new function(){
}
// Rebuild caches
- yield Zotero.Translators.reinit({ fromSchemaUpdate: true });
- yield Zotero.Styles.reinit({ fromSchemaUpdate: true });
+ yield Zotero.Translators.reinit({ fromSchemaUpdate: force != 1 });
+ yield Zotero.Styles.reinit({ fromSchemaUpdate: force != 1 });
}
catch (e) {
Zotero.debug(e, 1);
- if (!manual){
+ if (!force) {
_setRepositoryTimer(ZOTERO_CONFIG['REPOSITORY_RETRY_INTERVAL']);
}
return false;
@@ -1688,7 +1686,7 @@ Zotero.Schema = new function(){
yield _updateDBVersion('lastcheck', lastCheckTime);
})
.then(function () {
- if (!manual) {
+ if (!force) {
_setRepositoryTimer(ZOTERO_CONFIG['REPOSITORY_CHECK_INTERVAL']);
}