mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
refactor(statfs): switch back to statfs but convert values for smb
This commit is contained in:
@@ -41,7 +41,7 @@ export default function Layout({ loaderData }: Route.ComponentProps) {
|
||||
<span className="text-sm text-muted-foreground">
|
||||
Welcome, <span className="text-strong-accent">{loaderData.user?.username}</span>
|
||||
</span>
|
||||
<Button variant="outline" size="sm" onClick={() => logout.mutate({})} loading={logout.isPending}>
|
||||
<Button variant="default" size="sm" onClick={() => logout.mutate({})} loading={logout.isPending}>
|
||||
Logout
|
||||
</Button>
|
||||
<Button variant="default" size="sm" className="relative overflow-hidden">
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export const OPERATION_TIMEOUT = 5000;
|
||||
export const VOLUME_MOUNT_BASE = "/var/lib/docker/volumes/ironmount";
|
||||
export const VOLUME_MOUNT_BASE = "/var/lib/ironmount/volumes";
|
||||
export const DATABASE_URL = "/data/ironmount.db";
|
||||
export const RESTIC_PASS_FILE = "/data/secrets/restic.pass";
|
||||
|
||||
@@ -120,7 +120,7 @@ const getVolume = async (name: string) => {
|
||||
|
||||
let statfs: Partial<StatFs> = {};
|
||||
if (volume.status === "mounted") {
|
||||
statfs = (await getStatFs(`${VOLUME_MOUNT_BASE}/${name}/_data`).catch(() => {})) ?? {};
|
||||
statfs = await getStatFs(`${VOLUME_MOUNT_BASE}/${name}/_data`).catch(() => ({}));
|
||||
}
|
||||
|
||||
return { volume, statfs };
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import path from "node:path";
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { $ } from "bun";
|
||||
|
||||
type MountInfo = {
|
||||
@@ -60,18 +60,27 @@ export async function getMountForPath(p: string): Promise<MountInfo | undefined>
|
||||
}
|
||||
|
||||
export async function getStatFs(mountPoint: string) {
|
||||
const res = await $`df -Pk ${mountPoint}`.text();
|
||||
const s = await fs.statfs(mountPoint, { bigint: true });
|
||||
|
||||
const lines = res.trim().split("\n");
|
||||
if (lines.length < 2) {
|
||||
throw new Error(`Unexpected df output: ${res}`);
|
||||
}
|
||||
const unit = s.bsize > 0n ? s.bsize : 1n;
|
||||
|
||||
const parts = lines.at(-1)?.trim().split(/\s+/) as [string, string, string, string, string, string];
|
||||
const blocks = s.blocks > 0n ? s.blocks : 0n;
|
||||
|
||||
const total = Number(parts[1]) * 1024;
|
||||
const used = Number(parts[2]) * 1024;
|
||||
const free = Number(parts[3]) * 1024;
|
||||
let bfree = s.bfree > 0n ? s.bfree : 0n;
|
||||
if (bfree > blocks) bfree = blocks;
|
||||
|
||||
return { total, used, free };
|
||||
const bavail = s.bavail > 0n ? s.bavail : 0n;
|
||||
|
||||
const totalB = blocks * unit;
|
||||
const usedB = (blocks - bfree) * unit;
|
||||
const freeB = bavail * unit;
|
||||
|
||||
const MAX = BigInt(Number.MAX_SAFE_INTEGER);
|
||||
const toNumber = (x: bigint) => (x > MAX ? Number.MAX_SAFE_INTEGER : Number(x));
|
||||
|
||||
return {
|
||||
total: toNumber(totalB),
|
||||
used: toNumber(usedB),
|
||||
free: toNumber(freeB),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ services:
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
- /run/docker/plugins:/run/docker/plugins
|
||||
- /var/lib/docker/volumes/:/var/lib/docker/volumes:rshared
|
||||
- /var/lib/ironmount/volumes/:/var/lib/ironmount/volumes:rshared
|
||||
- ironmount_data:/data
|
||||
|
||||
- ./apps/client/app:/app/apps/client/app
|
||||
@@ -39,7 +39,7 @@ services:
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
- /run/docker/plugins:/run/docker/plugins
|
||||
- /var/lib/docker/volumes/:/var/lib/docker/volumes:rshared
|
||||
- /var/lib/ironmount/volumes/:/var/lib/ironmount/volumes:rshared
|
||||
- ironmount_data:/data
|
||||
|
||||
volumes:
|
||||
|
||||
Reference in New Issue
Block a user