Use the async shell exec

This commit is contained in:
Girish Ramakrishnan
2024-02-20 22:57:36 +01:00
parent 1128edc23e
commit b51071155a
3 changed files with 8 additions and 8 deletions
+6 -4
View File
@@ -68,8 +68,8 @@ async function hdparm(file) {
}
async function getSwaps() {
const stdout = safe.child_process.execSync('swapon --noheadings --raw --bytes --show=type,size,used,name', { encoding: 'utf8' });
if (!stdout) return {};
const [error, stdout] = await safe(shell.promises.exec('getSwaps', 'swapon --noheadings --raw --bytes --show=type,size,used,name', { encoding: 'utf8' }));
if (error) return {};
const swaps = {};
for (const line of stdout.trim().split('\n')) {
@@ -329,8 +329,10 @@ async function getLogs(unit, options) {
}
async function getBlockDevices() {
const info = safe.JSON.parse(safe.child_process.execSync('lsblk --paths --json --list --fs', { encoding: 'utf8' }));
if (!info) throw new BoxError(BoxError.INTERNAL_ERROR, safe.error.message);
const [error, result] = await safe(shell.promises.exec('getBlockDevices', 'lsblk --paths --json --list --fs', { encoding: 'utf8' }));
if (error) throw new BoxError(BoxError.INTERNAL_ERROR, `lsblk failed: ${error.message}`);
const info = safe.JSON.parse(result);
if (!info) throw new BoxError(BoxError.INTERNAL_ERROR, `failed to parse lsblk: ${safe.error.message}`);
const devices = info.blockdevices.filter(d => d.fstype === 'ext4' || d.fstype === 'xfs');