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?
This commit is contained in:
Dan Stillman 2016-12-13 01:25:56 -05:00
parent 747c11c917
commit 69430d74b2

View file

@ -967,10 +967,10 @@ Zotero.Schema = new function(){
/** /**
* Send XMLHTTP request for updated translators and styles to the central repository * Send XMLHTTP request for updated translators and styles to the central repository
* *
* @param {Boolean} force Force a repository query regardless of how * @param {Integer} [force=0] - If non-zero, force a repository query regardless of how long it's
* long it's been since the last check * 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 (!force) {
if (_remoteUpdateInProgress) { if (_remoteUpdateInProgress) {
Zotero.debug("A remote update is already in progress -- not checking repository"); Zotero.debug("A remote update is already in progress -- not checking repository");
@ -1025,13 +1025,11 @@ Zotero.Schema = new function(){
_remoteUpdateInProgress = true; _remoteUpdateInProgress = true;
if (force) { if (force == 2) {
if (force == 2) { url += '&m=2';
url += '&m=2'; }
} else if (force) {
else { url += '&m=1';
url += '&m=1';
}
} }
// Send list of installed styles // Send list of installed styles
@ -1054,7 +1052,7 @@ Zotero.Schema = new function(){
try { try {
var xmlhttp = yield Zotero.HTTP.request("POST", url, { body: body }); var xmlhttp = yield Zotero.HTTP.request("POST", url, { body: body });
return _updateFromRepositoryCallback(xmlhttp, !!force); return _updateFromRepositoryCallback(xmlhttp, force);
} }
catch (e) { catch (e) {
if (e instanceof Zotero.HTTP.UnexpectedStatusException if (e instanceof Zotero.HTTP.UnexpectedStatusException
@ -1493,7 +1491,7 @@ Zotero.Schema = new function(){
* *
* @return {Promise:Boolean} A promise for whether the update suceeded * @return {Promise:Boolean} A promise for whether the update suceeded
**/ **/
function _updateFromRepositoryCallback(xmlhttp, manual) { function _updateFromRepositoryCallback(xmlhttp, force) {
if (!xmlhttp.responseXML){ if (!xmlhttp.responseXML){
try { try {
if (xmlhttp.status>1000){ if (xmlhttp.status>1000){
@ -1509,7 +1507,7 @@ Zotero.Schema = new function(){
Zotero.debug('Repository cannot be contacted'); Zotero.debug('Repository cannot be contacted');
} }
if (!manual){ if (!force) {
_setRepositoryTimer(ZOTERO_CONFIG['REPOSITORY_RETRY_INTERVAL']); _setRepositoryTimer(ZOTERO_CONFIG['REPOSITORY_RETRY_INTERVAL']);
} }
@ -1642,7 +1640,7 @@ Zotero.Schema = new function(){
}) })
.then(function () { .then(function () {
Zotero.debug('All translators and styles are up-to-date'); Zotero.debug('All translators and styles are up-to-date');
if (!manual) { if (!force) {
_setRepositoryTimer(ZOTERO_CONFIG['REPOSITORY_CHECK_INTERVAL']); _setRepositoryTimer(ZOTERO_CONFIG['REPOSITORY_CHECK_INTERVAL']);
} }
@ -1664,12 +1662,12 @@ Zotero.Schema = new function(){
} }
// Rebuild caches // Rebuild caches
yield Zotero.Translators.reinit({ fromSchemaUpdate: true }); yield Zotero.Translators.reinit({ fromSchemaUpdate: force != 1 });
yield Zotero.Styles.reinit({ fromSchemaUpdate: true }); yield Zotero.Styles.reinit({ fromSchemaUpdate: force != 1 });
} }
catch (e) { catch (e) {
Zotero.debug(e, 1); Zotero.debug(e, 1);
if (!manual){ if (!force) {
_setRepositoryTimer(ZOTERO_CONFIG['REPOSITORY_RETRY_INTERVAL']); _setRepositoryTimer(ZOTERO_CONFIG['REPOSITORY_RETRY_INTERVAL']);
} }
return false; return false;
@ -1688,7 +1686,7 @@ Zotero.Schema = new function(){
yield _updateDBVersion('lastcheck', lastCheckTime); yield _updateDBVersion('lastcheck', lastCheckTime);
}) })
.then(function () { .then(function () {
if (!manual) { if (!force) {
_setRepositoryTimer(ZOTERO_CONFIG['REPOSITORY_CHECK_INTERVAL']); _setRepositoryTimer(ZOTERO_CONFIG['REPOSITORY_CHECK_INTERVAL']);
} }