shell: make shell.sudo promise based and waitable

This commit is contained in:
Girish Ramakrishnan
2025-07-16 21:53:22 +02:00
parent 32d07e7959
commit 989d843fcb
15 changed files with 86 additions and 64 deletions
+3 -3
View File
@@ -45,7 +45,7 @@ const REBOOT_CMD = path.join(__dirname, 'scripts/reboot.sh');
async function du(file) {
assert.strictEqual(typeof file, 'string');
const [error, stdoutResult] = await safe(shell.promises.sudo([ DU_CMD, file ], { captureStdout: true }));
const [error, stdoutResult] = await safe(shell.sudo([ DU_CMD, file ], { encoding: 'utf8' }));
if (error) throw new BoxError(BoxError.FS_ERROR, error);
return parseInt(stdoutResult.trim(), 10);
@@ -54,7 +54,7 @@ async function du(file) {
async function hdparm(file) {
assert.strictEqual(typeof file, 'string');
const [error, stdoutResult] = await safe(shell.promises.sudo([ HDPARM_CMD, file ], { captureStdout: true }));
const [error, stdoutResult] = await safe(shell.sudo([ HDPARM_CMD, file ], { encoding: 'utf8' }));
if (error) throw new BoxError(BoxError.FS_ERROR, error);
const lines = stdoutResult.split('\n');
@@ -279,7 +279,7 @@ async function updateDiskUsage(progressCallback) {
async function reboot() {
await notifications.unpin(notifications.TYPE_REBOOT, {});
const [error] = await safe(shell.promises.sudo([ REBOOT_CMD ], {}));
const [error] = await safe(shell.sudo([ REBOOT_CMD ], {}));
if (error) debug('reboot: could not reboot. %o', error);
}