Fix crash when system has no swap

This commit is contained in:
Girish Ramakrishnan
2024-03-22 10:39:35 +01:00
parent 4b4c8d8052
commit b66e77a2d8
+3 -1
View File
@@ -70,9 +70,11 @@ async function hdparm(file) {
async function getSwaps() {
const [error, stdout] = await safe(shell.exec('getSwaps', 'swapon --noheadings --raw --bytes --show=type,size,used,name', {}));
if (error) return {};
const output = stdout.trim();
if (!output) return {}; // no swaps
const swaps = {};
for (const line of stdout.trim().split('\n')) {
for (const line of output.split('\n')) {
const parts = line.split(' ', 4);
const name = parts[3];
swaps[name] = {