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()));
|
||||
}
|
||||
|
||||
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) {
|
||||
let data = [];
|
||||
lines.forEach(function (line) {
|
||||
@ -104,10 +120,9 @@ function fsSize(callback) {
|
||||
if (_linux) { cmd = 'df -lkPTx squashfs'; } // cmd = 'df -lkPTx squashfs | grep -E "^/|^.\\:"';
|
||||
if (_freebsd || _openbsd || _netbsd) { cmd = 'df -lkPT'; }
|
||||
exec(cmd, { maxBuffer: 1024 * 1024 }, function (error, stdout) {
|
||||
if (!error) {
|
||||
let lines = stdout.toString().split('\n');
|
||||
if (lines && lines[0] && lines[0].toLowerCase().startsWith('filesystem')) { lines.shift(); }
|
||||
let lines = filterLines(stdout);
|
||||
data = parseDf(lines);
|
||||
if (!error || data.length) {
|
||||
if (callback) {
|
||||
callback(data);
|
||||
}
|
||||
@ -115,8 +130,7 @@ function fsSize(callback) {
|
||||
} else {
|
||||
exec('df -kPT', { maxBuffer: 1024 * 1024 }, function (error, stdout) {
|
||||
if (!error) {
|
||||
let lines = stdout.toString().split('\n');
|
||||
if (lines && lines[0] && lines[0].toLowerCase().startsWith('filesystem')) { lines.shift(); }
|
||||
let lines = filterLines(stdout);
|
||||
data = parseDf(lines);
|
||||
}
|
||||
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 get(valuesObject: any, cb?: (data: any) => any): Promise<any>;
|
||||
export function observe(valuesObject: any, interval: number, cb?: (data: any) => any): number;
|
||||
|
||||
export function powerShellStart(): void;
|
||||
export function powerShellRelease(): void;
|
||||
|
||||
@ -396,6 +396,7 @@ function powerShellProceedResults(data) {
|
||||
}
|
||||
|
||||
function powerShellStart() {
|
||||
if (!_psChild) {
|
||||
_psChild = spawn('powershell.exe', ['-NoLogo', '-InputFormat', 'Text', '-NoExit', '-Command', '-'], {
|
||||
stdio: 'pipe',
|
||||
windowsHide: true,
|
||||
@ -422,16 +423,20 @@ function powerShellStart() {
|
||||
_psChild.kill();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function powerShellRelease() {
|
||||
try {
|
||||
if (_psChild) {
|
||||
_psChild.stdin.write('exit' + os.EOL);
|
||||
_psChild.stdin.end();
|
||||
_psPersistent = false;
|
||||
}
|
||||
} catch (e) {
|
||||
_psChild.kill();
|
||||
}
|
||||
_psChild = null;
|
||||
}
|
||||
|
||||
function powerShell(cmd) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user