fsSize() optimized parsing if there are errors
This commit is contained in:
parent
e7475d5ef2
commit
f7022c92f0
@ -54,6 +54,22 @@ function fsSize(callback) {
|
|||||||
return (linuxTmpFileSystems.includes(fs.toLowerCase()));
|
return (linuxTmpFileSystems.includes(fs.toLowerCase()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function filterLines(stdout) {
|
||||||
|
let lines = stdout.toString().split('\n');
|
||||||
|
if (stdout.toString().toLowerCase().indexOf('filesystem')) {
|
||||||
|
let removeLines = 0;
|
||||||
|
for (let i = 0; i < lines.length; i++) {
|
||||||
|
if (line[i] && lines[i].toLowerCase().startsWith('filesystem')) {
|
||||||
|
removeLines = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (let i = 0; i < removeLines; i++) {
|
||||||
|
lines.shift();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
|
|
||||||
function parseDf(lines) {
|
function parseDf(lines) {
|
||||||
let data = [];
|
let data = [];
|
||||||
lines.forEach(function (line) {
|
lines.forEach(function (line) {
|
||||||
@ -104,10 +120,9 @@ function fsSize(callback) {
|
|||||||
if (_linux) { cmd = 'df -lkPTx squashfs'; } // cmd = 'df -lkPTx squashfs | grep -E "^/|^.\\:"';
|
if (_linux) { cmd = 'df -lkPTx squashfs'; } // cmd = 'df -lkPTx squashfs | grep -E "^/|^.\\:"';
|
||||||
if (_freebsd || _openbsd || _netbsd) { cmd = 'df -lkPT'; }
|
if (_freebsd || _openbsd || _netbsd) { cmd = 'df -lkPT'; }
|
||||||
exec(cmd, { maxBuffer: 1024 * 1024 }, function (error, stdout) {
|
exec(cmd, { maxBuffer: 1024 * 1024 }, function (error, stdout) {
|
||||||
if (!error) {
|
let lines = filterLines(stdout);
|
||||||
let lines = stdout.toString().split('\n');
|
data = parseDf(lines);
|
||||||
if (lines && lines[0] && lines[0].toLowerCase().startsWith('filesystem')) { lines.shift(); }
|
if (!error || data.length) {
|
||||||
data = parseDf(lines);
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(data);
|
callback(data);
|
||||||
}
|
}
|
||||||
@ -115,8 +130,7 @@ function fsSize(callback) {
|
|||||||
} else {
|
} else {
|
||||||
exec('df -kPT', { maxBuffer: 1024 * 1024 }, function (error, stdout) {
|
exec('df -kPT', { maxBuffer: 1024 * 1024 }, function (error, stdout) {
|
||||||
if (!error) {
|
if (!error) {
|
||||||
let lines = stdout.toString().split('\n');
|
let lines = filterLines(stdout);
|
||||||
if (lines && lines[0] && lines[0].toLowerCase().startsWith('filesystem')) { lines.shift(); }
|
|
||||||
data = parseDf(lines);
|
data = parseDf(lines);
|
||||||
}
|
}
|
||||||
if (callback) {
|
if (callback) {
|
||||||
|
|||||||
3
lib/index.d.ts
vendored
3
lib/index.d.ts
vendored
@ -988,3 +988,6 @@ export function getDynamicData(srv?: string, iface?: string, cb?: (data: any) =>
|
|||||||
export function getAllData(srv?: string, iface?: string, cb?: (data: any) => any): Promise<any>;
|
export function getAllData(srv?: string, iface?: string, cb?: (data: any) => any): Promise<any>;
|
||||||
export function get(valuesObject: any, cb?: (data: any) => any): Promise<any>;
|
export function get(valuesObject: any, cb?: (data: any) => any): Promise<any>;
|
||||||
export function observe(valuesObject: any, interval: number, cb?: (data: any) => any): number;
|
export function observe(valuesObject: any, interval: number, cb?: (data: any) => any): number;
|
||||||
|
|
||||||
|
export function powerShellStart(): void;
|
||||||
|
export function powerShellRelease(): void;
|
||||||
|
|||||||
59
lib/util.js
59
lib/util.js
@ -396,42 +396,47 @@ function powerShellProceedResults(data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function powerShellStart() {
|
function powerShellStart() {
|
||||||
_psChild = spawn('powershell.exe', ['-NoLogo', '-InputFormat', 'Text', '-NoExit', '-Command', '-'], {
|
if (!_psChild) {
|
||||||
stdio: 'pipe',
|
_psChild = spawn('powershell.exe', ['-NoLogo', '-InputFormat', 'Text', '-NoExit', '-Command', '-'], {
|
||||||
windowsHide: true,
|
stdio: 'pipe',
|
||||||
maxBuffer: 1024 * 20000,
|
windowsHide: true,
|
||||||
encoding: 'UTF-8',
|
maxBuffer: 1024 * 20000,
|
||||||
env: util._extend({}, process.env, { LANG: 'en_US.UTF-8' })
|
encoding: 'UTF-8',
|
||||||
});
|
env: util._extend({}, process.env, { LANG: 'en_US.UTF-8' })
|
||||||
if (_psChild && _psChild.pid) {
|
|
||||||
_psPersistent = true;
|
|
||||||
_psChild.stdout.on('data', function (data) {
|
|
||||||
_psResult = _psResult + data.toString('utf8');
|
|
||||||
if (data.indexOf(_psCmdSeperator) >= 0) {
|
|
||||||
powerShellProceedResults(_psResult);
|
|
||||||
_psResult = '';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
_psChild.stderr.on('data', function () {
|
|
||||||
powerShellProceedResults(_psResult + _psError);
|
|
||||||
});
|
|
||||||
_psChild.on('error', function () {
|
|
||||||
powerShellProceedResults(_psResult + _psError);
|
|
||||||
});
|
|
||||||
_psChild.on('close', function () {
|
|
||||||
_psChild.kill();
|
|
||||||
});
|
});
|
||||||
|
if (_psChild && _psChild.pid) {
|
||||||
|
_psPersistent = true;
|
||||||
|
_psChild.stdout.on('data', function (data) {
|
||||||
|
_psResult = _psResult + data.toString('utf8');
|
||||||
|
if (data.indexOf(_psCmdSeperator) >= 0) {
|
||||||
|
powerShellProceedResults(_psResult);
|
||||||
|
_psResult = '';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
_psChild.stderr.on('data', function () {
|
||||||
|
powerShellProceedResults(_psResult + _psError);
|
||||||
|
});
|
||||||
|
_psChild.on('error', function () {
|
||||||
|
powerShellProceedResults(_psResult + _psError);
|
||||||
|
});
|
||||||
|
_psChild.on('close', function () {
|
||||||
|
_psChild.kill();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function powerShellRelease() {
|
function powerShellRelease() {
|
||||||
try {
|
try {
|
||||||
_psChild.stdin.write('exit' + os.EOL);
|
if (_psChild) {
|
||||||
_psChild.stdin.end();
|
_psChild.stdin.write('exit' + os.EOL);
|
||||||
_psPersistent = false;
|
_psChild.stdin.end();
|
||||||
|
_psPersistent = false;
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_psChild.kill();
|
_psChild.kill();
|
||||||
}
|
}
|
||||||
|
_psChild = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function powerShell(cmd) {
|
function powerShell(cmd) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user