SEARCH-444

- Created an api to clear the user index data folder
This commit is contained in:
Keerthi Niranjan
2017-11-21 22:14:27 +05:30
parent f2f1eb2cd6
commit 9e6a7df281
4 changed files with 36 additions and 30 deletions

View File

@@ -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
};