From 98aa53de077d27009591b3884c1a6a28ab7d9840 Mon Sep 17 00:00:00 2001 From: Beaudan Date: Fri, 1 Mar 2019 13:58:06 +1100 Subject: [PATCH 1/2] Await removing databse --- main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.js b/main.js index 253ba553c..6cf89e376 100644 --- a/main.js +++ b/main.js @@ -755,7 +755,7 @@ function getDefaultSQLKey() { async function removeDB() { const userDir = await getRealPath(app.getPath('userData')); - sql.removeDB(userDir); + await sql.removeDB(userDir); try { userConfig.remove(); From d317b020f06221a11fd82600e180df4fa1ea0c69 Mon Sep 17 00:00:00 2001 From: Beaudan Date: Fri, 1 Mar 2019 15:15:30 +1100 Subject: [PATCH 2/2] Close the database if the password is incorrect, fixes windows crash --- app/sql.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/sql.js b/app/sql.js index 8a60085cc..cf8fb38ac 100644 --- a/app/sql.js +++ b/app/sql.js @@ -679,13 +679,21 @@ async function initialize({ configDir, key }) { // console._log(`EXPLAIN QUERY PLAN ${statement}\n`, data && data.detail); // }); - await setupSQLCipher(promisified, { key }); - await updateSchema(promisified); + try { + await setupSQLCipher(promisified, { key }); + await updateSchema(promisified); + } catch (e) { + await promisified.close(); + throw e; + } db = promisified; } async function close() { + if (!db) { + return; + } const dbRef = db; db = null; await dbRef.close();