From 9fd24a8761e65fbc759db69aea5dd719935dd6a1 Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Wed, 16 Nov 2016 10:03:51 +0100 Subject: [PATCH] fixed small bug in blockDevices --- CHANGELOG.md | 1 + lib/filesystem.js | 66 +++++++++++++++++++++++------------------------ lib/index.js | 1 + 3 files changed, 35 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3498bf6..5b8a6e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 | diff --git a/lib/filesystem.js b/lib/filesystem.js index b764e9e..896eb18 100644 --- a/lib/filesystem.js +++ b/lib/filesystem.js @@ -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]) }) } }); diff --git a/lib/index.js b/lib/index.js index 2588cf0..d7cc1d1 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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