fix: statfs when volume is not mounted

This commit is contained in:
Nicolas Meienberger
2025-09-25 21:28:36 +02:00
parent 6b386d28d6
commit 9b57dd8a1c
4 changed files with 52 additions and 5 deletions

View File

@@ -10,7 +10,7 @@ import { db } from "../../db/db";
import { volumesTable } from "../../db/schema";
import { createVolumeBackend } from "../backends/backend";
import { toMessage } from "../../utils/errors";
import { getStatFs } from "../../utils/mountinfo";
import { getStatFs, type StatFs } from "../../utils/mountinfo";
import { VOLUME_MOUNT_BASE } from "../../core/constants";
const listVolumes = async () => {
@@ -101,12 +101,15 @@ const getVolume = async (name: string) => {
where: eq(volumesTable.name, name),
});
const statfs = await getStatFs(`${VOLUME_MOUNT_BASE}/${name}/_data`).catch(() => {});
if (!volume) {
throw new NotFoundError("Volume not found");
}
let statfs: Partial<StatFs> = {};
if (volume.status === "mounted") {
statfs = (await getStatFs(`${VOLUME_MOUNT_BASE}/${name}/_data`).catch(() => {})) ?? {};
}
return { volume, statfs };
};

View File

@@ -6,6 +6,12 @@ type MountInfo = {
fstype: string;
};
export type StatFs = {
total: number;
used: number;
free: number;
};
function isPathWithin(base: string, target: string): boolean {
const rel = path.posix.relative(base, target);
return rel === "" || (!rel.startsWith("..") && !path.isAbsolute(rel));