From a50b7ef04aad86ed2a19dc9b136773bc16ffdcb0 Mon Sep 17 00:00:00 2001 From: Martynas Bagdonas Date: Tue, 19 Mar 2024 11:59:18 +0200 Subject: [PATCH] Finish dictionary installation even if file cleanup fails (on Windows) --- chrome/content/zotero/xpcom/dictionaries.js | 24 ++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/chrome/content/zotero/xpcom/dictionaries.js b/chrome/content/zotero/xpcom/dictionaries.js index 4cdabf0cb0..0354893f51 100644 --- a/chrome/content/zotero/xpcom/dictionaries.js +++ b/chrome/content/zotero/xpcom/dictionaries.js @@ -136,20 +136,11 @@ Zotero.Dictionaries = new function () { } zipReader.close(); - zipReader = null + zipReader = null; Cu.forceGC(); - await OS.File.remove(xpiPath); await _loadDirectory(dir); } catch (e) { - try { - if (await OS.File.exists(xpiPath)) { - await OS.File.remove(xpiPath); - } - } - catch (e) { - Zotero.logError(e); - } try { if (await OS.File.exists(dir)) { await OS.File.removeDir(dir); @@ -160,6 +151,19 @@ Zotero.Dictionaries = new function () { } throw e; } + finally { + // Remove the downloaded file from the temp path + // Note: In same cases, on Windows, it can't be removed + // because something is keeping it open + try { + if (await OS.File.exists(xpiPath)) { + await OS.File.remove(xpiPath); + } + } + catch (e) { + Zotero.logError(e); + } + } }; /**