diff --git a/js/search/searchConfig.js b/js/search/searchConfig.js index bab0a58d..a390771b 100644 --- a/js/search/searchConfig.js +++ b/js/search/searchConfig.js @@ -33,6 +33,8 @@ const launchAgentFile = path.join(libraryFolderPath, 'search-launch-agent.sh'); const launchDaemonFile = path.join(libraryFolderPath, 'search-launch-daemon.sh'); const windowsTaskFile = path.join(pathToUtils, isDevEnv ? 'ClearSchTasks/bin/Release/ClearSchTasks.exe' : 'ClearSchTasks.exe'); const windowsClearScript = path.join(pathToUtils, isDevEnv ? 'ClearOnBoot/bin/Release/ClearOnBoot.exe' : 'ClearOnBoot.exe'); +const freeDiskSpace = path.join(pathToUtils, isDevEnv ? 'FreeDiskSpace/bin/Release/FreeDiskSpace.exe' : 'FreeDiskSpace.exe'); + const libraryPaths = { INDEX_VALIDATOR: indexValidatorPath, @@ -45,6 +47,7 @@ const libraryPaths = { LAUNCH_DAEMON_FILE: launchDaemonFile, WINDOWS_TASK_FILE: windowsTaskFile, WINDOWS_CLEAR_SCRIPT: windowsClearScript, + FREE_DISK_SPACE: freeDiskSpace, }; const folderPaths = { @@ -70,6 +73,8 @@ const searchConfig = { LIBRARY_CONSTANTS: libraryPaths, FOLDERS_CONSTANTS: folderPaths, TAR_LZ4_EXT: '.tar.lz4', + DISK_NOT_READY: 'NOT_READY', + DISK_NOT_FOUND: 'DISK_NOT_FOUND', RANDOM_STRING: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", MINIMUM_DISK_SPACE: 300000000, // in bytes PERMISSION_ERROR: "The FSUTIL utility requires that you have administrative privileges.", diff --git a/js/search/searchUtils.js b/js/search/searchUtils.js index e225a776..00f9d2a8 100644 --- a/js/search/searchUtils.js +++ b/js/search/searchUtils.js @@ -22,7 +22,7 @@ class SearchUtils { return new Promise((resolve, reject) => { if (!isMac) { try { - this.path = this.path.substring(0, 2); + this.path = this.path.substring(0, 1); } catch (e) { reject(new Error('Invalid Path : ' + e)); } diff --git a/js/search/utils/checkDiskSpace.js b/js/search/utils/checkDiskSpace.js index 84a9f8be..9e81c2c6 100644 --- a/js/search/utils/checkDiskSpace.js +++ b/js/search/utils/checkDiskSpace.js @@ -1,6 +1,8 @@ const { exec } = require('child_process'); const { isMac } = require('../../utils/misc'); const searchConfig = require('../searchConfig.js'); +const log = require('../../log.js'); +const logLevels = require('../../enums/logLevels.js'); function checkDiskSpace(path, resolve, reject) { if (!path) { @@ -25,25 +27,25 @@ function checkDiskSpace(path, resolve, reject) { return resolve(space >= searchConfig.MINIMUM_DISK_SPACE); }); } else { - exec(`fsutil volume diskfree ${path}`, (error, stdout) => { - if (error) { - if (stdout.indexOf(searchConfig.WIN_PATH_ERROR) !== -1) { - return reject(new Error(`${searchConfig.WIN_PATH_ERROR} ${error}`)); - } - 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(searchConfig.PERMISSION_ERROR) !== -1) { - // this is temporary until we use the custom exe file. - return resolve(true); - } - let data = stdout.trim().split("\n"); + exec(`"${searchConfig.LIBRARY_CONSTANTS.FREE_DISK_SPACE}" ${path}`, (error, stdout, stderr) => { - let disk_info_str = data[data.length - 1].split(':'); - return resolve(disk_info_str[1] >= searchConfig.MINIMUM_DISK_SPACE); + if (error) { + log.send(logLevels.ERROR, `Error retrieving free disk space : ${error}`); + log.send(logLevels.ERROR, `Error stderr: ${stderr}`); + } + + let data = stdout.trim().split(","); + + if (data[ 1 ] === searchConfig.DISK_NOT_READY) { + return reject(new Error("Error : Disk not ready")); + } + + if (data[ 1 ] === searchConfig.DISK_NOT_FOUND) { + return reject(new Error("Error : Disk not found")); + } + + let disk_info_str = data[ 0 ]; + return resolve(disk_info_str >= searchConfig.MINIMUM_DISK_SPACE); }); } }