mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-29 14:45:24 +00:00
fix: show disk usage for the mount being browsed (#1347)
This commit is contained in:
1 parent
e3eada899c
commit
da588f8fa1
3 files changed
+56
-3
No files matched your search
@@ -27,7 +27,7 @@ import {
|
|||||||
removeFolderShortcut,
|
removeFolderShortcut,
|
||||||
} from "./api/file-manager-data-api";
|
} from "./api/file-manager-data-api";
|
||||||
import { listSSHFiles } from "./api/ssh-file-operations-api";
|
import { listSSHFiles } from "./api/ssh-file-operations-api";
|
||||||
import type { DiskFilesystem } from "./disk-info";
|
import { mountForPath, type DiskFilesystem } from "./disk-info";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import FolderTree from "./components/FolderTree";
|
import FolderTree from "./components/FolderTree";
|
||||||
import {
|
import {
|
||||||
@@ -702,11 +702,13 @@ export function FileManagerSidebar({
|
|||||||
// ─── Render ───────────────────────────────────────────────────────────────────
|
// ─── Render ───────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
const storageFilesystems = diskInfo?.filesystems ?? [];
|
const storageFilesystems = diskInfo?.filesystems ?? [];
|
||||||
const activeStorageMount = selectedMount ?? diskInfo?.mount ?? null;
|
const pathFs = mountForPath(storageFilesystems, currentPath);
|
||||||
|
const activeStorageMount =
|
||||||
|
selectedMount ?? pathFs?.mount ?? diskInfo?.mount ?? null;
|
||||||
const selectedFs =
|
const selectedFs =
|
||||||
selectedMount !== null
|
selectedMount !== null
|
||||||
? (storageFilesystems.find((fs) => fs.mount === selectedMount) ?? null)
|
? (storageFilesystems.find((fs) => fs.mount === selectedMount) ?? null)
|
||||||
: null;
|
: pathFs;
|
||||||
|
|
||||||
const storage =
|
const storage =
|
||||||
selectedFs && selectedFs.percent !== null
|
selectedFs && selectedFs.percent !== null
|
||||||
|
|||||||
@@ -20,3 +20,19 @@ export interface HostDiskInfo {
|
|||||||
mount: string | null;
|
mount: string | null;
|
||||||
filesystems?: DiskFilesystem[];
|
filesystems?: DiskFilesystem[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The filesystem the path lives on: the longest mount point that holds it. */
|
||||||
|
export function mountForPath(
|
||||||
|
filesystems: DiskFilesystem[],
|
||||||
|
path: string | null | undefined,
|
||||||
|
): DiskFilesystem | null {
|
||||||
|
if (!path) return null;
|
||||||
|
let best: DiskFilesystem | null = null;
|
||||||
|
for (const fs of filesystems) {
|
||||||
|
const mount = fs.mount.replace(/\/+$/, "") || "/";
|
||||||
|
const inside =
|
||||||
|
mount === "/" || path === mount || path.startsWith(`${mount}/`);
|
||||||
|
if (inside && (!best || mount.length > best.mount.length)) best = fs;
|
||||||
|
}
|
||||||
|
return best;
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import {
|
||||||
|
mountForPath,
|
||||||
|
type DiskFilesystem,
|
||||||
|
} from "../../src/frontend/disk-info";
|
||||||
|
|
||||||
|
function fs(mount: string): DiskFilesystem {
|
||||||
|
return {
|
||||||
|
filesystem: mount,
|
||||||
|
type: "ext4",
|
||||||
|
mount,
|
||||||
|
percent: 10,
|
||||||
|
usedHuman: "1G",
|
||||||
|
totalHuman: "10G",
|
||||||
|
availableHuman: "9G",
|
||||||
|
usedBytes: 1,
|
||||||
|
totalBytes: 10,
|
||||||
|
availableBytes: 9,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("mountForPath", () => {
|
||||||
|
const list = [fs("/"), fs("/volume1"), fs("/volume10")];
|
||||||
|
|
||||||
|
it("picks the deepest mount that holds the path", () => {
|
||||||
|
expect(mountForPath(list, "/volume1/share")?.mount).toBe("/volume1");
|
||||||
|
expect(mountForPath(list, "/volume10")?.mount).toBe("/volume10");
|
||||||
|
expect(mountForPath(list, "/etc")?.mount).toBe("/");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns null without a path or mounts", () => {
|
||||||
|
expect(mountForPath(list, null)).toBeNull();
|
||||||
|
expect(mountForPath([], "/etc")).toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in new issue
Block a user