commit d88cfc6c5f95796dc6cf885665c9f3623f7a9b8f
parent c6a2057340c010e95f79fad4c69775fc9690ba4f
Author: Dan Stillman <dstillman@zotero.org>
Date: Tue, 15 Nov 2016 03:36:35 -0500
Make Zotero.Styles/Translators.init() wait until bundled files are updated
Fixes #1123, Quick Copy error in console with new data directory
Diffstat:
2 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/chrome/content/zotero/xpcom/schema.js b/chrome/content/zotero/xpcom/schema.js
@@ -465,17 +465,17 @@ Zotero.Schema = new function(){
// Update files
switch (mode) {
case 'styles':
- yield Zotero.Styles.init();
+ yield Zotero.Styles.reinit({ fromSchemaUpdate: true, noReinit: true });
var updated = yield _updateBundledFilesAtLocation(installLocation, mode);
case 'translators':
- yield Zotero.Translators.init();
+ yield Zotero.Translators.reinit({ fromSchemaUpdate: true, noReinit: true });
var updated = yield _updateBundledFilesAtLocation(installLocation, mode);
default:
- yield Zotero.Translators.init();
+ yield Zotero.Translators.reinit({ fromSchemaUpdate: true, noReinit: true });
let up1 = yield _updateBundledFilesAtLocation(installLocation, 'translators', true);
- yield Zotero.Styles.init();
+ yield Zotero.Styles.reinit({ fromSchemaUpdate: true, noReinit: true });
let up2 = yield _updateBundledFilesAtLocation(installLocation, 'styles');
var updated = up1 || up2;
}
@@ -952,7 +952,8 @@ Zotero.Schema = new function(){
});
yield Zotero[Mode].reinit({
- metadataCache: cache
+ metadataCache: cache,
+ fromSchemaUpdate: true
});
return true;
diff --git a/chrome/content/zotero/xpcom/translation/translators.js b/chrome/content/zotero/xpcom/translation/translators.js
@@ -43,6 +43,18 @@ Zotero.Translators = new function() {
* available (e.g., in updateBundledFiles()), to avoid unnecesary file reads
*/
this.reinit = Zotero.Promise.coroutine(function* (options = {}) {
+ // Wait until bundled files have been updated, except when this is called by the schema update
+ // code itself
+ if (!options.fromSchemaUpdate) {
+ yield Zotero.Schema.schemaUpdatePromise;
+ }
+ // Before bundled files can be updated, any existing translators need to be loaded, but other
+ // init() calls from elsewhere should still wait on schemaUpdatePromise, so init()/lazy()
+ // can't be used. Instead, the schema update code calls reinit() with noReinit.
+ else if (options.noReinit && _initialized) {
+ return;
+ }
+
Zotero.debug("Initializing translators");
var start = new Date;