shell: rework code to use shell.spawn

spawn gives out streams and we have more control over the stdout/stderr
buffers. otherwise, we have to provide a max buffer capture size to exec
This commit is contained in:
Girish Ramakrishnan
2024-10-15 10:10:15 +02:00
parent 7b648cddfd
commit 6c3ca9c364
18 changed files with 101 additions and 88 deletions
+2 -2
View File
@@ -37,7 +37,7 @@ function parseLine(line) {
}
async function disks() {
const [error, output] = await safe(shell.exec('df -B1 --output=source,fstype,size,used,avail,pcent,target', { timeout: 5000 }));
const [error, output] = await safe(shell.spawn('df', ['-B1', '--output=source,fstype,size,used,avail,pcent,target'], { encoding: 'utf8', timeout: 5000 }));
if (error) {
debug(`disks: df command failed. error: ${error}\n stdout: ${error.stdout}\n stderr: ${error.stderr}`);
throw new BoxError(BoxError.FS_ERROR, `Error running df: ${error.message}`);
@@ -54,7 +54,7 @@ async function disks() {
async function file(filename) {
assert.strictEqual(typeof filename, 'string');
const [error, output] = await safe(shell.exec(`df -B1 --output=source,fstype,size,used,avail,pcent,target ${filename}`, { timeout: 5000 }));
const [error, output] = await safe(shell.spawn('df', ['-B1', '--output=source,fstype,size,used,avail,pcent,target', filename], { encoding: 'utf8', timeout: 5000 }));
if (error) {
debug(`file: df command failed. error: ${error}\n stdout: ${error.stdout}\n stderr: ${error.stderr}`);
throw new BoxError(BoxError.FS_ERROR, `Error running df: ${error.message}`);