From ba342d571e1e25c8f1655ec208c8125c3cba7eba Mon Sep 17 00:00:00 2001 From: Keerthi Niranjan Date: Thu, 15 Feb 2018 11:06:49 +0530 Subject: [PATCH 1/5] SEARCH-605 - Permission error on windows 7 temporary fix --- js/search/utils/checkDiskSpace.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/js/search/utils/checkDiskSpace.js b/js/search/utils/checkDiskSpace.js index f8d1c729..85dc6c98 100644 --- a/js/search/utils/checkDiskSpace.js +++ b/js/search/utils/checkDiskSpace.js @@ -25,13 +25,21 @@ function checkDiskSpace(path, resolve, reject) { return resolve(space >= searchConfig.MINIMUM_DISK_SPACE); }); } else { - exec(`fsutil volume diskfree ${path}`, (error, stdout, stderr) => { + exec(`fsutil volume diskfree ${path}`, (error, stdout) => { if (error) { - if (stderr.indexOf("No such file or directory") !== -1) { + if (stdout.indexOf("Error: The system cannot find the path specified.") !== -1) { return reject(new Error("No such file or directory : " + error)); } + if (stdout.indexOf("The FSUTIL utility requires that you have administrative privileges.") !== -1) { + // this is temporary until we use the custom exe file. + return true; + } return reject(new Error("Error : " + error)); } + if (stdout.indexOf("The FSUTIL utility requires that you have administrative privileges.") !== -1) { + // this is temporary until we use the custom exe file. + return true; + } let data = stdout.trim().split("\n"); let disk_info_str = data[data.length - 1].split(':'); From 0ee004ccf1782918d0b4f3d0c7a8217536b79b68 Mon Sep 17 00:00:00 2001 From: Keerthi Niranjan Date: Thu, 15 Feb 2018 12:20:52 +0530 Subject: [PATCH 2/5] SEARCH-605 - Updated unit tests --- tests/Search.test.js | 2 +- tests/SearchUtils.test.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/Search.test.js b/tests/Search.test.js index cb49e735..ffdb8772 100644 --- a/tests/Search.test.js +++ b/tests/Search.test.js @@ -59,7 +59,7 @@ describe('Tests for Search', function() { tempBatchPath = path.join(userConfigDir, 'data', 'temp_batch_indexes'); dataFolderPath = path.join(userConfigDir, 'data'); if (fs.existsSync(dataFolderPath)) { - fs.unlinkSync(dataFolderPath) + deleteIndexFolders(dataFolderPath) } done(); }); diff --git a/tests/SearchUtils.test.js b/tests/SearchUtils.test.js index 28278d6f..c429876d 100644 --- a/tests/SearchUtils.test.js +++ b/tests/SearchUtils.test.js @@ -33,6 +33,9 @@ describe('Tests for Search Utils', function() { beforeAll(function (done) { executionPath = path.join(__dirname, 'library'); + if (!isMac) { + executionPath = path.join(__dirname, '..', 'library'); + } userConfigDir = path.join(__dirname, '..'); searchConfig = require('../js/search/searchConfig.js'); const { SearchUtils } = require('../js/search/searchUtils.js'); From a71a62720d36554de0c713ad87e47cacde4467a7 Mon Sep 17 00:00:00 2001 From: Keerthi Niranjan Date: Thu, 15 Feb 2018 14:00:53 +0530 Subject: [PATCH 3/5] SEARCH-605 - return resolve missing --- js/search/utils/checkDiskSpace.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/search/utils/checkDiskSpace.js b/js/search/utils/checkDiskSpace.js index 85dc6c98..78aba530 100644 --- a/js/search/utils/checkDiskSpace.js +++ b/js/search/utils/checkDiskSpace.js @@ -32,13 +32,13 @@ function checkDiskSpace(path, resolve, reject) { } if (stdout.indexOf("The FSUTIL utility requires that you have administrative privileges.") !== -1) { // this is temporary until we use the custom exe file. - return true; + return resolve(true); } return reject(new Error("Error : " + error)); } if (stdout.indexOf("The FSUTIL utility requires that you have administrative privileges.") !== -1) { // this is temporary until we use the custom exe file. - return true; + return resolve(true); } let data = stdout.trim().split("\n"); From 48fe7a6fbedcd1bfb400a99ab5a9f313b81e0910 Mon Sep 17 00:00:00 2001 From: Keerthi Niranjan Date: Fri, 16 Feb 2018 13:32:50 +0530 Subject: [PATCH 4/5] SEARCH-605 - Review comments fix --- js/search/searchConfig.js | 5 ++++- js/search/utils/checkDiskSpace.js | 12 ++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/js/search/searchConfig.js b/js/search/searchConfig.js index 7d424bdc..170c7582 100644 --- a/js/search/searchConfig.js +++ b/js/search/searchConfig.js @@ -57,7 +57,10 @@ const searchConfig = { LIBRARY_CONSTANTS: libraryPaths, FOLDERS_CONSTANTS: folderPaths, TAR_LZ4_EXT: '.tar.lz4', - MINIMUM_DISK_SPACE: 300000000 // in bytes + MINIMUM_DISK_SPACE: 300000000, // in bytes + PERMISSION_ERROR: "The FSUTIL utility requires that you have administrative privileges.", + WIN_PATH_ERROR: "Error: The system cannot find the path specified.", + MAC_PATH_ERROR: "No such file or directory" }; module.exports = searchConfig; diff --git a/js/search/utils/checkDiskSpace.js b/js/search/utils/checkDiskSpace.js index 78aba530..84a9f8be 100644 --- a/js/search/utils/checkDiskSpace.js +++ b/js/search/utils/checkDiskSpace.js @@ -11,8 +11,8 @@ function checkDiskSpace(path, resolve, reject) { if (isMac) { exec("df -k '" + path.replace(/'/g,"'\\''") + "'", (error, stdout, stderr) => { if (error) { - if (stderr.indexOf("No such file or directory") !== -1) { - return reject(new Error("No such file or directory : " + error)) + if (stderr.indexOf(searchConfig.MAC_PATH_ERROR) !== -1) { + return reject(new Error(`${searchConfig.MAC_PATH_ERROR} ${error}`)) } return reject(new Error("Error : " + error)); } @@ -27,16 +27,16 @@ function checkDiskSpace(path, resolve, reject) { } else { exec(`fsutil volume diskfree ${path}`, (error, stdout) => { if (error) { - if (stdout.indexOf("Error: The system cannot find the path specified.") !== -1) { - return reject(new Error("No such file or directory : " + error)); + if (stdout.indexOf(searchConfig.WIN_PATH_ERROR) !== -1) { + return reject(new Error(`${searchConfig.WIN_PATH_ERROR} ${error}`)); } - if (stdout.indexOf("The FSUTIL utility requires that you have administrative privileges.") !== -1) { + if (stdout.indexOf(searchConfig.PERMISSION_ERROR) !== -1) { // this is temporary until we use the custom exe file. return resolve(true); } return reject(new Error("Error : " + error)); } - if (stdout.indexOf("The FSUTIL utility requires that you have administrative privileges.") !== -1) { + if (stdout.indexOf(searchConfig.PERMISSION_ERROR) !== -1) { // this is temporary until we use the custom exe file. return resolve(true); } From 6449393c7f9a9bef5e47232bb9981c61eb96d373 Mon Sep 17 00:00:00 2001 From: Keerthi Niranjan Date: Fri, 16 Feb 2018 13:44:52 +0530 Subject: [PATCH 5/5] SEARCH-605 - Changed the check --- tests/Search.test.js | 4 ++-- tests/SearchUtils.test.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/Search.test.js b/tests/Search.test.js index ffdb8772..756cf235 100644 --- a/tests/Search.test.js +++ b/tests/Search.test.js @@ -1,7 +1,7 @@ const childProcess = require('child_process'); const path = require('path'); const fs = require('fs'); -const { isMac } = require('../js/utils/misc.js'); +const { isWindowsOS } = require('../js/utils/misc.js'); let executionPath = null; let userConfigDir = null; @@ -46,7 +46,7 @@ describe('Tests for Search', function() { key = 'jjjehdnctsjyieoalskcjdhsnahsadndfnusdfsdfsd='; executionPath = path.join(__dirname, 'library'); - if (!isMac) { + if (isWindowsOS) { executionPath = path.join(__dirname, '..', 'library'); } userConfigDir = path.join(__dirname, '..'); diff --git a/tests/SearchUtils.test.js b/tests/SearchUtils.test.js index c429876d..eac2964b 100644 --- a/tests/SearchUtils.test.js +++ b/tests/SearchUtils.test.js @@ -1,6 +1,6 @@ const fs = require('fs'); const path = require('path'); -const { isMac } = require('../js/utils/misc.js'); +const { isMac, isWindowsOS } = require('../js/utils/misc.js'); let executionPath = null; let userConfigDir = null; @@ -33,7 +33,7 @@ describe('Tests for Search Utils', function() { beforeAll(function (done) { executionPath = path.join(__dirname, 'library'); - if (!isMac) { + if (isWindowsOS) { executionPath = path.join(__dirname, '..', 'library'); } userConfigDir = path.join(__dirname, '..'); @@ -84,7 +84,7 @@ describe('Tests for Search Utils', function() { it('should return error invalid path', function (done) { const checkFreeSpace = jest.spyOn(SearchUtilsAPI, 'checkFreeSpace'); SearchUtilsAPI.path = './tp'; - if (!isMac) { + if (isWindowsOS) { SearchUtilsAPI.path = 'A://test'; } SearchUtilsAPI.checkFreeSpace().catch(function (err) {