mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
fix: statfs when volume is not mounted
This commit is contained in:
@@ -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 };
|
||||
};
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user