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,
|
||||
'serial': disk.serial,
|
||||
'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(/MODEL=/g, ',"model":')
|
||||
.replace(/OWNER=/g, ',"owner":')
|
||||
.replace(/GROUP=/g, ',"group":')
|
||||
.replace(/\n/g, '}\n');
|
||||
}
|
||||
|
||||
@ -715,9 +717,19 @@ function diskLayout(callback) {
|
||||
if (!error) {
|
||||
try {
|
||||
const out = stdout.toString().trim();
|
||||
let devices = [];
|
||||
try {
|
||||
const outJSON = JSON.parse(out);
|
||||
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) => {
|
||||
let mediumType = '';
|
||||
const BSDName = '/dev/' + device.name;
|
||||
@ -753,7 +765,6 @@ function diskLayout(callback) {
|
||||
});
|
||||
cmd = cmd + 'printf "\n' + BSDName + '|"; smartctl -H ' + BSDName + ' | grep overall;';
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
util.noop();
|
||||
}
|
||||
@ -811,7 +822,6 @@ function diskLayout(callback) {
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
}
|
||||
|
||||
if (_darwin) {
|
||||
exec('system_profiler SPSerialATADataType SPNVMeDataType', function (error, stdout) {
|
||||
if (!error) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user