fixed small bug in blockDevices

This commit is contained in:
Sebastian Hildebrandt 2016-11-16 10:03:51 +01:00
parent 126a1fb35e
commit 9fd24a8761
3 changed files with 35 additions and 33 deletions

View File

@ -89,6 +89,7 @@ Other changes
| Version | Date | Comment | | Version | Date | Comment |
| -------------- | -------------- | -------- | | -------------- | -------------- | -------- |
| 3.11.1 | 2016-11-16 | fixed small bug in blockDevices |
| 3.11.0 | 2016-11-15 | blockDevices for OSX and extended blockDevices | | 3.11.0 | 2016-11-15 | blockDevices for OSX and extended blockDevices |
| 3.10.2 | 2016-11-14 | bug fix fsSize on OSX | | 3.10.2 | 2016-11-14 | bug fix fsSize on OSX |
| 3.10.1 | 2016-11-14 | optimization fsStats, disksIO, networkStats | | 3.10.1 | 2016-11-14 | optimization fsStats, disksIO, networkStats |

View File

@ -73,10 +73,10 @@ exports.fsSize = fsSize;
// disks // disks
function parseBytes(s) { function parseBytes(s) {
return parseInt(s.substr(s.indexOf(' (')+2, s.indexOf(' Bytes)')-10)) return parseInt(s.substr(s.indexOf(' (') + 2, s.indexOf(' Bytes)') - 10))
} }
function parseDevices (lines) { function parseDevices(lines) {
let devices = []; let devices = [];
let i = 0; let i = 0;
lines.forEach(line => { lines.forEach(line => {
@ -86,20 +86,20 @@ function parseDevices (lines) {
} else { } else {
let parts = line.split(':'); let parts = line.split(':');
if (parts.length > 1) { if (parts.length > 1) {
if (!devices[i]) devices[i] = { if (!devices[i]) devices[i] = {
name: '', name: '',
identifier: '', identifier: '',
type: 'disk', type: 'disk',
fstype: '', fstype: '',
mount: '', mount: '',
size: 0, size: 0,
physical: 'HDD', physical: 'HDD',
uuid: '', uuid: '',
label: '', label: '',
model: '', model: '',
serial: '', serial: '',
protocol: '' protocol: ''
}; };
parts[0] = parts[0].trim().toUpperCase().replace(/ +/g, ''); parts[0] = parts[0].trim().toUpperCase().replace(/ +/g, '');
parts[1] = parts[1].trim(); parts[1] = parts[1].trim();
if ('DEVICEIDENTIFIER' == parts[0]) devices[i].identifier = parts[1]; if ('DEVICEIDENTIFIER' == parts[0]) devices[i].identifier = parts[1];
@ -123,16 +123,16 @@ function parseDevices (lines) {
} }
function fromTo(header, label) { function fromTo(header, label) {
let from = header.indexOf(label); let from = header.indexOf(label);
let to = from + label.length; let to = from + label.length;
for (let i = to; i < header.length && header[i] == ' '; i++) { for (let i = to; i < header.length && header[i] == ' '; i++) {
to = i to = i
} }
console.log(label + ' - ' + from + ' ' + to); console.log(label + ' - ' + from + ' ' + to);
return { return {
from: from, from: from,
to: to to: to
} }
} }
function blockDevices(callback) { function blockDevices(callback) {
@ -159,8 +159,8 @@ function blockDevices(callback) {
if (orgline != '') { if (orgline != '') {
if (orgline.substr(header.indexOf('FSTYPE'), 1) == ' ') { orgline = orgline.substr(0, header.indexOf('FSTYPE')) + '-' + orgline.substr(header.indexOf('FSTYPE') + 1, 1000)} if (orgline.substr(header.indexOf('FSTYPE'), 1) == ' ') { orgline = orgline.substr(0, header.indexOf('FSTYPE')) + '-' + orgline.substr(header.indexOf('FSTYPE') + 1, 1000)}
if (orgline.substr(header.indexOf('MOUNTPOINT'), 1) == ' ') { orgline = orgline.substr(0, header.indexOf('MOUNTPOINT')) + '-' + orgline.substr(header.indexOf('MOUNTPOINT') + 1, 1000)} if (orgline.substr(header.indexOf('MOUNTPOINT'), 1) == ' ') { orgline = orgline.substr(0, header.indexOf('MOUNTPOINT')) + '-' + orgline.substr(header.indexOf('MOUNTPOINT') + 1, 1000)}
if (orgline.substr(header.indexOf('UUID'), 1) == ' ') { orgline = orgline.substr(0, header.indexOf('UUID')) + '-' + orgline.substr(header.indexOf('UUID') + 1, 1000)} if (orgline.substr(header.indexOf('UUID'), 1) == ' ') { orgline = orgline.substr(0, header.indexOf('UUID')) + '-' + orgline.substr(header.indexOf('UUID') + 1, 1000)}
if (orgline.substr(header.indexOf('TRAN'), 1) == ' ') { orgline = orgline.substr(0, header.indexOf('TRAN')) + '-' + orgline.substr(header.indexOf('TRAN') + 1, 1000)} if (orgline.substr(header.indexOf('TRAN'), 1) == ' ') { orgline = orgline.substr(0, header.indexOf('TRAN')) + '-' + orgline.substr(header.indexOf('TRAN') + 1, 1000)}
let line = orgline.replace(/[├─│└]+/g, ""); let line = orgline.replace(/[├─│└]+/g, "");
line = line.replace(/ +/g, " ").trim().split(' '); line = line.replace(/ +/g, " ").trim().split(' ');
data.push({ data.push({
@ -170,11 +170,11 @@ function blockDevices(callback) {
'mount': (line[4] == '-' ? '' : line[4]), 'mount': (line[4] == '-' ? '' : line[4]),
'size': parseInt(line[2]), 'size': parseInt(line[2]),
'physical': (line[1] == 'disk' ? (line[6] == '0' ? 'SSD' : 'HDD') : (line[1] == 'rom' ? 'CD/DVD' : '')), 'physical': (line[1] == 'disk' ? (line[6] == '0' ? 'SSD' : 'HDD') : (line[1] == 'rom' ? 'CD/DVD' : '')),
'uuid': (line[5] == '-' ? '' : line[5]), 'uuid': (line[5] == '-' ? '' : line[5]),
'label': orgline.substring(ft_label.from, ft_label.to).trim(), 'label': orgline.substring(ft_label.from, ft_label.to).trim(),
'model': orgline.substring(ft_model.from, ft_model.to).trim(), 'model': orgline.substring(ft_model.from, ft_model.to).trim(),
'serial': orgline.substring(ft_serial.from, ft_serial.to).trim(), 'serial': orgline.substring(ft_serial.from, ft_serial.to).trim(),
'protocol': (line[8] == '-' ? '' : line[8]) 'protocol': (line[8] == '-' ? '' : line[8])
}) })
} }
}); });

View File

@ -81,6 +81,7 @@
// -------------------------------- // --------------------------------
// //
// version date comment // version date comment
// 3.11.1 2016-11-16 fixed small bug in blockDevices
// 3.11.0 2016-11-15 blockDevices for OSX and extended blockDevices // 3.11.0 2016-11-15 blockDevices for OSX and extended blockDevices
// 3.10.2 2016-11-14 bug fix fsSize on OSX // 3.10.2 2016-11-14 bug fix fsSize on OSX
// 3.10.1 2016-11-14 optimization fsStats, disksIO, networkStats // 3.10.1 2016-11-14 optimization fsStats, disksIO, networkStats