blockDevices: improved for older lsblk versions
This commit is contained in:
parent
9418044263
commit
216f23c74e
@ -89,6 +89,7 @@ Other changes
|
|||||||
|
|
||||||
| Version | Date | Comment |
|
| Version | Date | Comment |
|
||||||
| -------------- | -------------- | -------- |
|
| -------------- | -------------- | -------- |
|
||||||
|
| 3.11.2 | 2016-11-16 | blockDevices: improved for older lsblk versions |
|
||||||
| 3.11.1 | 2016-11-16 | fixed small bug in blockDevices |
|
| 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 |
|
||||||
|
|||||||
@ -128,33 +128,20 @@ function fromTo(header, label) {
|
|||||||
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);
|
|
||||||
return {
|
return {
|
||||||
from: from,
|
from: from,
|
||||||
to: to
|
to: to
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function blockDevices(callback) {
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
function parseBlk(lines) {
|
||||||
process.nextTick(() => {
|
|
||||||
if (_windows) {
|
|
||||||
let error = new Error(NOT_SUPPORTED);
|
|
||||||
if (callback) { callback(NOT_SUPPORTED) }
|
|
||||||
reject(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_linux) {
|
|
||||||
// see https://wiki.ubuntuusers.de/lsblk/
|
|
||||||
exec("lsblk -bo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,TRAN,SERIAL,LABEL,MODEL,OWNER,GROUP,MODE,ALIGNMENT,MIN-IO,OPT-IO,PHY-SEC,LOG-SEC,SCHED,RQ-SIZE,RA,WSAME", function (error, stdout) {
|
|
||||||
let data = [];
|
|
||||||
if (!error) {
|
|
||||||
let lines = stdout.toString().split('\n');
|
|
||||||
let header = lines[0];
|
let header = lines[0];
|
||||||
let ft_label = fromTo(header, 'LABEL');
|
let ft_label = fromTo(header, 'LABEL');
|
||||||
let ft_model = fromTo(header, 'MODEL');
|
let ft_model = fromTo(header, 'MODEL');
|
||||||
let ft_serial = fromTo(header, 'SERIAL');
|
let ft_serial = fromTo(header, 'SERIAL');
|
||||||
lines.splice(0, 1);
|
lines.splice(0, 1);
|
||||||
|
|
||||||
|
let data = [];
|
||||||
lines.forEach(orgline => {
|
lines.forEach(orgline => {
|
||||||
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)}
|
||||||
@ -173,13 +160,43 @@ function blockDevices(callback) {
|
|||||||
'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': (ft_serial.from >= 0 ? orgline.substring(ft_serial.from, ft_serial.to).trim() : ''),
|
||||||
'protocol': (line[8] == '-' ? '' : line[8])
|
'protocol': (ft_serial.from >= 0 && line[8] == '-' ? '' : line[8])
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
data = util.unique(data);
|
data = util.unique(data);
|
||||||
data = util.sortByKey(data, ['type', 'name']);
|
data = util.sortByKey(data, ['type', 'name']);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
function blockDevices(callback) {
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
process.nextTick(() => {
|
||||||
|
if (_windows) {
|
||||||
|
let error = new Error(NOT_SUPPORTED);
|
||||||
|
if (callback) { callback(NOT_SUPPORTED) }
|
||||||
|
reject(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_linux) {
|
||||||
|
// see https://wiki.ubuntuusers.de/lsblk/
|
||||||
|
// exec("lsblk -bo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,TRAN,SERIAL,LABEL,MODEL,OWNER,GROUP,MODE,ALIGNMENT,MIN-IO,OPT-IO,PHY-SEC,LOG-SEC,SCHED,RQ-SIZE,RA,WSAME", function (error, stdout) {
|
||||||
|
exec("lsblk -bo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,TRAN,SERIAL,LABEL,MODEL,OWNER", function (error, stdout) {
|
||||||
|
let data = [];
|
||||||
|
if (!error) {
|
||||||
|
let lines = stdout.toString().split('\n');
|
||||||
|
data = parseBlk(lines);
|
||||||
|
if (callback) {
|
||||||
|
callback(data)
|
||||||
|
}
|
||||||
|
resolve(data);
|
||||||
|
} else {
|
||||||
|
exec("lsblk -bo NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID,ROTA,RO,LABEL,MODEL,OWNER", function (error, stdout) {
|
||||||
|
if (!error) {
|
||||||
|
let lines = stdout.toString().split('\n');
|
||||||
|
data = parseBlk(lines);
|
||||||
}
|
}
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(data)
|
callback(data)
|
||||||
@ -187,6 +204,8 @@ function blockDevices(callback) {
|
|||||||
resolve(data);
|
resolve(data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
if (_darwin) {
|
if (_darwin) {
|
||||||
// last minute decision to remove code ... not stable
|
// last minute decision to remove code ... not stable
|
||||||
exec("diskutil info -all", function (error, stdout) {
|
exec("diskutil info -all", function (error, stdout) {
|
||||||
|
|||||||
@ -81,6 +81,7 @@
|
|||||||
// --------------------------------
|
// --------------------------------
|
||||||
//
|
//
|
||||||
// version date comment
|
// version date comment
|
||||||
|
// 3.11.2 2016-11-16 blockDevices: improved for older lsblk versions
|
||||||
// 3.11.1 2016-11-16 fixed small bug in blockDevices
|
// 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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user