From fb670ad6b96aa40a499db64ed656fe849ed143a0 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Thu, 1 Nov 2018 16:40:19 -0700 Subject: [PATCH] Remove IndexedDB files after removing IndexedDB database --- app/sql.js | 17 +++++++++++++++++ js/background.js | 1 + js/modules/data.js | 5 +++++ ts/util/lint/exceptions.json | 8 ++++---- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/app/sql.js b/app/sql.js index 66c2d71ed339..6699a0df55bf 100644 --- a/app/sql.js +++ b/app/sql.js @@ -14,6 +14,7 @@ module.exports = { initialize, close, removeDB, + removeIndexedDBFiles, createOrUpdateGroup, getGroupById, @@ -453,6 +454,7 @@ async function updateSchema(instance) { let db; let filePath; +let indexedDBPath; async function initialize({ configDir, key }) { if (db) { @@ -466,10 +468,13 @@ async function initialize({ configDir, key }) { throw new Error('initialize: key` is required!'); } + indexedDBPath = path.join(configDir, 'IndexedDB'); + const dbDir = path.join(configDir, 'sql'); mkdirp.sync(dbDir); filePath = path.join(dbDir, 'db.sqlite'); + const sqlInstance = await openDatabase(filePath); const promisified = promisify(sqlInstance); @@ -502,6 +507,18 @@ async function removeDB() { rimraf.sync(filePath); } +async function removeIndexedDBFiles() { + if (!indexedDBPath) { + throw new Error( + 'removeIndexedDBFiles: Need to initialize and set indexedDBPath first!' + ); + } + + const pattern = path.join(indexedDBPath, '*.leveldb'); + rimraf.sync(pattern); + indexedDBPath = null; +} + const GROUPS_TABLE = 'groups'; async function createOrUpdateGroup(data) { return createOrUpdate(GROUPS_TABLE, data); diff --git a/js/background.js b/js/background.js index 04115f6ca89e..ca6eb226465d 100644 --- a/js/background.js +++ b/js/background.js @@ -297,6 +297,7 @@ await mandatoryMessageUpgrade({ upgradeMessageSchema }); await migrateAllToSQLCipher({ writeNewAttachmentData, Views }); await removeDatabase(); + await window.Signal.Data.removeIndexedDBFiles(); window.installStorage(window.newStorage); await window.storage.fetch(); diff --git a/js/modules/data.js b/js/modules/data.js index cc2b6ddd6cc6..ae886c20630f 100644 --- a/js/modules/data.js +++ b/js/modules/data.js @@ -41,6 +41,7 @@ module.exports = { close, removeDB, + removeIndexedDBFiles, createOrUpdateGroup, getGroupById, @@ -319,6 +320,10 @@ async function removeDB() { await channels.removeDB(); } +async function removeIndexedDBFiles() { + await channels.removeIndexedDBFiles(); +} + // Groups async function createOrUpdateGroup(data) { diff --git a/ts/util/lint/exceptions.json b/ts/util/lint/exceptions.json index c19a2ca276c5..5d1996c51261 100644 --- a/ts/util/lint/exceptions.json +++ b/ts/util/lint/exceptions.json @@ -227,7 +227,7 @@ "rule": "jQuery-load(", "path": "js/background.js", "line": " await ConversationController.load();", - "lineNumber": 404, + "lineNumber": 405, "reasonCategory": "falseMatch", "updated": "2018-10-02T21:00:44.007Z" }, @@ -235,7 +235,7 @@ "rule": "jQuery-$(", "path": "js/background.js", "line": " el: $('body'),", - "lineNumber": 467, + "lineNumber": 468, "reasonCategory": "usageTrusted", "updated": "2018-10-16T23:47:48.006Z", "reasonDetail": "Protected from arbitrary input" @@ -244,7 +244,7 @@ "rule": "jQuery-wrap(", "path": "js/background.js", "line": " wrap(", - "lineNumber": 725, + "lineNumber": 726, "reasonCategory": "falseMatch", "updated": "2018-10-18T22:23:00.485Z" }, @@ -252,7 +252,7 @@ "rule": "jQuery-wrap(", "path": "js/background.js", "line": " await wrap(", - "lineNumber": 1215, + "lineNumber": 1227, "reasonCategory": "falseMatch", "updated": "2018-10-26T22:43:23.229Z" },