From 219dec1c9ca601e73bb3943a0c9af98257794265 Mon Sep 17 00:00:00 2001 From: Nicolas Meienberger Date: Fri, 17 Oct 2025 21:34:40 +0200 Subject: [PATCH] fix(statfs): fix usage graph by using df command --- apps/server/src/utils/mountinfo.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/apps/server/src/utils/mountinfo.ts b/apps/server/src/utils/mountinfo.ts index 466fa23..c51e0ca 100644 --- a/apps/server/src/utils/mountinfo.ts +++ b/apps/server/src/utils/mountinfo.ts @@ -1,5 +1,6 @@ import path from "node:path"; import fs from "node:fs/promises"; +import { $ } from "bun"; type MountInfo = { mountPoint: string; @@ -59,11 +60,18 @@ export async function getMountForPath(p: string): Promise } export async function getStatFs(mountPoint: string) { - const stats = await fs.statfs(mountPoint); + const res = await $`df -Pk ${mountPoint}`.text(); - const total = Number(stats.blocks) * Number(stats.bsize); - const free = Number(stats.bfree) * Number(stats.bsize); - const used = total - free; + const lines = res.trim().split("\n"); + if (lines.length < 2) { + throw new Error(`Unexpected df output: ${res}`); + } + + const parts = lines.at(-1)?.trim().split(/\s+/) as [string, string, string, string, string, string]; + + const total = Number(parts[1]) * 1024; + const used = Number(parts[2]) * 1024; + const free = Number(parts[3]) * 1024; return { total, used, free }; }