mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-01-07 06:33:58 -06:00
988439b780
- User config unit tests
45 lines
1.6 KiB
JavaScript
45 lines
1.6 KiB
JavaScript
const { exec } = require('child_process');
|
|
const { isMac } = require('../../utils/misc');
|
|
const searchConfig = require('../searchConfig.js');
|
|
|
|
function checkDiskSpace(path, resolve, reject) {
|
|
if (!path) {
|
|
reject(new Error("Please provide path"));
|
|
return;
|
|
}
|
|
|
|
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))
|
|
}
|
|
return reject(new Error("Error : " + error));
|
|
}
|
|
|
|
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(' ');
|
|
let space = freeSpace[3] * 1024;
|
|
return resolve(space >= searchConfig.MINIMUM_DISK_SPACE);
|
|
});
|
|
} else {
|
|
exec(`fsutil volume diskfree ${path}`, (error, stdout, stderr) => {
|
|
if (error) {
|
|
if (stderr.indexOf("No such file or directory") !== -1) {
|
|
return reject(new Error("No such file or directory : " + error));
|
|
}
|
|
return reject(new Error("Error : " + error));
|
|
}
|
|
let data = stdout.trim().split("\n");
|
|
|
|
let disk_info_str = data[data.length - 1].split(':');
|
|
return resolve(disk_info_str[1] >= searchConfig.MINIMUM_DISK_SPACE);
|
|
});
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
checkDiskSpace: checkDiskSpace
|
|
}; |