2017-12-14 14:16:00 +05:30
|
|
|
const { exec } = require('child_process');
|
|
|
|
|
const { isMac } = require('../../utils/misc');
|
2017-12-29 17:36:40 +05:30
|
|
|
const searchConfig = require('../searchConfig.js');
|
2017-12-14 14:16:00 +05:30
|
|
|
|
2017-12-29 17:36:40 +05:30
|
|
|
function checkDiskSpace(path, resolve, reject) {
|
2017-12-14 14:16:00 +05:30
|
|
|
if (!path) {
|
2017-12-29 17:36:40 +05:30
|
|
|
reject(new Error("Please provide path"));
|
|
|
|
|
return;
|
2017-12-14 14:16:00 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isMac) {
|
|
|
|
|
exec("df -k '" + path.replace(/'/g,"'\\''") + "'", (error, stdout, stderr) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
if (stderr.indexOf("No such file or directory") !== -1) {
|
2017-12-29 17:36:40 +05:30
|
|
|
return reject(new Error("No such file or directory : " + error))
|
2017-12-14 14:16:00 +05:30
|
|
|
}
|
2017-12-29 17:36:40 +05:30
|
|
|
return reject(new Error("Error : " + error));
|
2017-12-14 14:16:00 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let data = stdout.trim().split("\n");
|
|
|
|
|
|
|
|
|
|
let disk_info_str = data[data.length - 1].replace( /[\s\n\r]+/g,' ');
|
|
|
|
|
let freeSpace = disk_info_str.split(' ');
|
2017-12-29 17:36:40 +05:30
|
|
|
let space = freeSpace[3] * 1024;
|
|
|
|
|
return resolve(space >= searchConfig.MINIMUM_DISK_SPACE);
|
2017-12-14 14:16:00 +05:30
|
|
|
});
|
|
|
|
|
} else {
|
2018-02-15 11:06:49 +05:30
|
|
|
exec(`fsutil volume diskfree ${path}`, (error, stdout) => {
|
2017-12-14 14:16:00 +05:30
|
|
|
if (error) {
|
2018-02-15 11:06:49 +05:30
|
|
|
if (stdout.indexOf("Error: The system cannot find the path specified.") !== -1) {
|
2017-12-29 17:36:40 +05:30
|
|
|
return reject(new Error("No such file or directory : " + error));
|
2017-12-14 14:16:00 +05:30
|
|
|
}
|
2018-02-15 11:06:49 +05:30
|
|
|
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;
|
|
|
|
|
}
|
2017-12-29 17:36:40 +05:30
|
|
|
return reject(new Error("Error : " + error));
|
2017-12-14 14:16:00 +05:30
|
|
|
}
|
2018-02-15 11:06:49 +05:30
|
|
|
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;
|
|
|
|
|
}
|
2017-12-14 14:16:00 +05:30
|
|
|
let data = stdout.trim().split("\n");
|
|
|
|
|
|
|
|
|
|
let disk_info_str = data[data.length - 1].split(':');
|
2017-12-29 17:36:40 +05:30
|
|
|
return resolve(disk_info_str[1] >= searchConfig.MINIMUM_DISK_SPACE);
|
2017-12-14 14:16:00 +05:30
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
checkDiskSpace: checkDiskSpace
|
|
|
|
|
};
|