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 |
| -------------- | -------------- | -------- |
| 3.11.1 | 2016-11-16 | fixed small bug in 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.1 | 2016-11-14 | optimization fsStats, disksIO, networkStats |

View File

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

View File

@ -81,6 +81,7 @@
// --------------------------------
//
// 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.10.2 2016-11-14 bug fix fsSize on OSX
// 3.10.1 2016-11-14 optimization fsStats, disksIO, networkStats