From d88cfc6c5f95796dc6cf885665c9f3623f7a9b8f Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 15 Nov 2016 03:36:35 -0500 Subject: [PATCH] Make Zotero.Styles/Translators.init() wait until bundled files are updated Fixes #1123, Quick Copy error in console with new data directory --- chrome/content/zotero/xpcom/schema.js | 11 ++++++----- .../content/zotero/xpcom/translation/translators.js | 12 ++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/chrome/content/zotero/xpcom/schema.js b/chrome/content/zotero/xpcom/schema.js index f758e0ad0..639b2aac8 100644 --- 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 index 32bf62c29..d8b2d2979 100644 --- 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;