diff options
| author | ko1N <ko1N1337@gmail.com> | 2025-06-10 19:25:58 +0200 |
|---|---|---|
| committer | ko1N <ko1N1337@gmail.com> | 2025-06-10 19:25:58 +0200 |
| commit | a2531a588f6bffeb1d55fe5b870d1e524d90ac32 (patch) | |
| tree | 6668dbfab6f79370a3453662fd9512690ec4ee25 /services/SystemUsage.qml | |
| parent | readme: add how to start in usage section (diff) | |
| download | caelestia-shell-a2531a588f6bffeb1d55fe5b870d1e524d90ac32.tar.gz caelestia-shell-a2531a588f6bffeb1d55fe5b870d1e524d90ac32.tar.bz2 caelestia-shell-a2531a588f6bffeb1d55fe5b870d1e524d90ac32.zip | |
Fix disk usage when using lvm
Diffstat (limited to 'services/SystemUsage.qml')
| -rw-r--r-- | services/SystemUsage.qml | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/services/SystemUsage.qml b/services/SystemUsage.qml index 1de0c57..ef953f1 100644 --- a/services/SystemUsage.qml +++ b/services/SystemUsage.qml @@ -97,19 +97,39 @@ Singleton { id: storage running: true - command: ["sh", "-c", "df | grep '^/dev/' | awk '{print $3, $4}'"] + command: ["sh", "-c", "df | grep '^/dev/' | awk '{print $1, $3, $4}'"] stdout: SplitParser { splitMarker: "" onRead: data => { - let used = 0; - let avail = 0; - for (const line of data.trim().split("\n")) { - const [u, a] = line.split(" "); - used += parseInt(u, 10); - avail += parseInt(a, 10); - } - root.storageUsed = used; - root.storageTotal = used + avail; + const deviceMap = new Map(); + + for (const line of data.trim().split("\n")) { + if (line.trim() === "") continue; + + const parts = line.trim().split(/\s+/); + if (parts.length >= 3) { + const device = parts[0]; + const used = parseInt(parts[1], 10) || 0; + const avail = parseInt(parts[2], 10) || 0; + + // only keep the entry with the largest total space for each device + if (!deviceMap.has(device) || + (used + avail) > (deviceMap.get(device).used + deviceMap.get(device).avail)) { + deviceMap.set(device, { used: used, avail: avail }); + } + } + } + + let totalUsed = 0; + let totalAvail = 0; + + for (const [device, stats] of deviceMap) { + totalUsed += stats.used; + totalAvail += stats.avail; + } + + root.storageUsed = totalUsed; + root.storageTotal = totalUsed + totalAvail; } } } |