diskLayout() support for older versions of lsblk
This commit is contained in:
parent
24e8145a43
commit
0fd3c20474
@ -244,7 +244,8 @@ function parseBlk(lines) {
|
|||||||
'model': disk.model,
|
'model': disk.model,
|
||||||
'serial': disk.serial,
|
'serial': disk.serial,
|
||||||
'removable': disk.rm === '1',
|
'removable': disk.rm === '1',
|
||||||
'protocol': disk.tran
|
'protocol': disk.tran,
|
||||||
|
'group': disk.group,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -269,6 +270,7 @@ function blkStdoutToObject(stdout) {
|
|||||||
.replace(/LABEL=/g, ',"label":')
|
.replace(/LABEL=/g, ',"label":')
|
||||||
.replace(/MODEL=/g, ',"model":')
|
.replace(/MODEL=/g, ',"model":')
|
||||||
.replace(/OWNER=/g, ',"owner":')
|
.replace(/OWNER=/g, ',"owner":')
|
||||||
|
.replace(/GROUP=/g, ',"group":')
|
||||||
.replace(/\n/g, '}\n');
|
.replace(/\n/g, '}\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -715,9 +717,19 @@ function diskLayout(callback) {
|
|||||||
if (!error) {
|
if (!error) {
|
||||||
try {
|
try {
|
||||||
const out = stdout.toString().trim();
|
const out = stdout.toString().trim();
|
||||||
|
let devices = [];
|
||||||
|
try {
|
||||||
const outJSON = JSON.parse(out);
|
const outJSON = JSON.parse(out);
|
||||||
if (outJSON && outJSON.hasOwnProperty('blockdevices')) {
|
if (outJSON && outJSON.hasOwnProperty('blockdevices')) {
|
||||||
let devices = outJSON.blockdevices.filter(item => { return item.group === 'disk' && item.size > 0 && item.model !== null; });
|
devices = outJSON.blockdevices.filter(item => { return item.group === 'disk' && item.size > 0 && item.model !== null; });
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// fallback to older version of lsblk
|
||||||
|
const out2 = execSync('export LC_ALL=C; lsblk -bPo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,RM,LABEL,MODEL,OWNER,GROUP; unset LC_ALL').toString();
|
||||||
|
let lines = blkStdoutToObject(out2).split('\n');
|
||||||
|
const data = parseBlk(lines);
|
||||||
|
devices = data.filter(item => { return item.group === 'disk' && item.size > 0 && item.model !== null && item.model !== ''; });
|
||||||
|
}
|
||||||
devices.forEach((device) => {
|
devices.forEach((device) => {
|
||||||
let mediumType = '';
|
let mediumType = '';
|
||||||
const BSDName = '/dev/' + device.name;
|
const BSDName = '/dev/' + device.name;
|
||||||
@ -753,7 +765,6 @@ function diskLayout(callback) {
|
|||||||
});
|
});
|
||||||
cmd = cmd + 'printf "\n' + BSDName + '|"; smartctl -H ' + BSDName + ' | grep overall;';
|
cmd = cmd + 'printf "\n' + BSDName + '|"; smartctl -H ' + BSDName + ' | grep overall;';
|
||||||
});
|
});
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
util.noop();
|
util.noop();
|
||||||
}
|
}
|
||||||
@ -811,7 +822,6 @@ function diskLayout(callback) {
|
|||||||
if (callback) { callback(result); }
|
if (callback) { callback(result); }
|
||||||
resolve(result);
|
resolve(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_darwin) {
|
if (_darwin) {
|
||||||
exec('system_profiler SPSerialATADataType SPNVMeDataType', function (error, stdout) {
|
exec('system_profiler SPSerialATADataType SPNVMeDataType', function (error, stdout) {
|
||||||
if (!error) {
|
if (!error) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user