From 9e6a7df2818dc4aa526f06923cfd13e379ba5740 Mon Sep 17 00:00:00 2001 From: Keerthi Niranjan Date: Tue, 21 Nov 2017 22:14:27 +0530 Subject: [PATCH] SEARCH-444 - Created an api to clear the user index data folder --- js/cryptoLib/index.js | 26 -------------------------- js/main.js | 5 ++--- js/preload/preloadMain.js | 5 +++++ js/search/search.js | 30 +++++++++++++++++++++++++++++- 4 files changed, 36 insertions(+), 30 deletions(-) diff --git a/js/cryptoLib/index.js b/js/cryptoLib/index.js index 99395acb..e8013bff 100644 --- a/js/cryptoLib/index.js +++ b/js/cryptoLib/index.js @@ -119,32 +119,6 @@ class Crypto { }); }); } - - /** - * Deleting the data index folder - * when the app is closed - */ - deleteFolders() { - Crypto.deleteFolderRecursive(this.dataFolder); - } - - /** - * Removing all the folders and files inside the data folder - * @param location - */ - static deleteFolderRecursive(location) { - if (fs.existsSync(location)) { - fs.readdirSync(location).forEach((file) => { - let curPath = location + "/" + file; - if (fs.lstatSync(curPath).isDirectory()) { - Crypto.deleteFolderRecursive(curPath); - } else { - fs.unlinkSync(curPath); - } - }); - fs.rmdirSync(location); - } - } } module.exports = Crypto; \ No newline at end of file diff --git a/js/main.js b/js/main.js index a1ca5049..e5973bb5 100644 --- a/js/main.js +++ b/js/main.js @@ -18,8 +18,7 @@ const protocolHandler = require('./protocolHandler'); const getCmdLineArg = require('./utils/getCmdLineArg.js'); const log = require('./log.js'); const logLevels = require('./enums/logLevels.js'); -const Crypto = require('./cryptoLib'); -const crypto = new Crypto(); +const { clearIndexFolder } = require('./search/search'); require('electron-dl')(); @@ -132,7 +131,7 @@ app.on('activate', function() { app.on('will-quit', function (e) { e.preventDefault(); - crypto.deleteFolders(); + clearIndexFolder(); app.exit(); }); diff --git a/js/preload/preloadMain.js b/js/preload/preloadMain.js index c9f64cd1..4254147b 100644 --- a/js/preload/preloadMain.js +++ b/js/preload/preloadMain.js @@ -136,6 +136,11 @@ function createAPI() { */ Search: remote.require('./search/search.js').Search, + /** + * Function to clear the user index data + */ + clearIndexFolder: remote.require('./search/search.js').clearIndexFolder, + /** * Brings window forward and gives focus. * @param {String} windowName Name of window. Note: main window name is 'main' diff --git a/js/search/search.js b/js/search/search.js index 7e2a6f2e..13a6f27a 100644 --- a/js/search/search.js +++ b/js/search/search.js @@ -513,6 +513,33 @@ class Search { throw new Error(err); } } + + /** + * Removing all the folders and files inside the data folder + * @param location + */ + static deleteFolderRecursive(location) { + if (fs.existsSync(location)) { + fs.readdirSync(location).forEach((file) => { + let curPath = location + "/" + file; + if (fs.lstatSync(curPath).isDirectory()) { + Search.deleteFolderRecursive(curPath); + } else { + fs.unlinkSync(curPath); + } + }); + fs.rmdirSync(location); + } + } + +} + +/** + * Deleting the data index folder + * when the app is closed + */ +function clearIndexFolder() { + Search.deleteFolderRecursive(INDEX_DATA_FOLDER); } /** @@ -520,5 +547,6 @@ class Search { * @type {{Search: Search}} */ module.exports = { - Search: Search + Search: Search, + clearIndexFolder: clearIndexFolder };