Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
123 lines
3.3 KiB
TypeScript
123 lines
3.3 KiB
TypeScript
export interface MountedDiskUsage {
|
|
capacityKey?: string;
|
|
filesystemType?: string;
|
|
mountPoint: string;
|
|
used: number;
|
|
total: number;
|
|
}
|
|
|
|
export interface AggregatedDiskUsage {
|
|
used: number;
|
|
total: number;
|
|
percent: number;
|
|
}
|
|
|
|
/** Network/FUSE sources that report cloud quotas, not local block capacity. */
|
|
export function isNetworkOrFuseCapacityKey(capacityKey: string | undefined): boolean {
|
|
const key = capacityKey?.trim();
|
|
if (!key) return false;
|
|
const lower = key.toLowerCase();
|
|
if (lower === "fuse" || lower.startsWith("fuse.")) return true;
|
|
if (lower === "/dev/fuse" || lower.endsWith("/fuse")) return true;
|
|
if (lower === "rclone" || lower.startsWith("rclone:")) return true;
|
|
if (lower.includes("clouddrive")) return true;
|
|
// CIFS/SMB (`//server/share`) and NFS (`host:/export` or `[ipv6]:/export`).
|
|
// Keep synthetic local keys such as APFS pools and overlay/overlayfs roots
|
|
// out of this heuristic.
|
|
if (lower.startsWith("//")) return true;
|
|
if (
|
|
!lower.startsWith("apfs:")
|
|
&& !lower.startsWith("overlay:")
|
|
&& !lower.startsWith("overlayfs:")
|
|
&& /^([a-z0-9._-]+|\[[0-9a-f:]+(?:%[a-z0-9._-]+)?\]):\//.test(lower)
|
|
) {
|
|
return true;
|
|
}
|
|
if (
|
|
lower === "sshfs"
|
|
|| lower === "s3fs"
|
|
|| lower === "gcsfuse"
|
|
|| lower === "mergerfs"
|
|
|| lower === "unionfs"
|
|
|| lower === "unionfs-fuse"
|
|
|| lower === "ceph"
|
|
|| lower === "ceph-fuse"
|
|
|| lower === "cephfs"
|
|
|| lower === "gluster"
|
|
|| lower === "glusterfs"
|
|
|| lower === "ufs"
|
|
) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
export function isNetworkOrFuseFilesystemType(filesystemType: string | undefined): boolean {
|
|
const type = filesystemType?.trim().toLowerCase();
|
|
if (!type) return false;
|
|
if (type.includes("clouddrive")) return true;
|
|
if (
|
|
/^fuse\.(rclone|sshfs|s3fs|gcsfuse|ufs|mergerfs|unionfs|unionfs-fuse|ceph|ceph-fuse|cephfs|glusterfs)$/
|
|
.test(type)
|
|
) {
|
|
return true;
|
|
}
|
|
return [
|
|
"fuse",
|
|
"rclone",
|
|
"sshfs",
|
|
"s3fs",
|
|
"gcsfuse",
|
|
"mergerfs",
|
|
"unionfs",
|
|
"unionfs-fuse",
|
|
"nfs",
|
|
"nfs4",
|
|
"cifs",
|
|
"smb",
|
|
"smb3",
|
|
"smbfs",
|
|
"afs",
|
|
"ceph",
|
|
"cephfs",
|
|
"glusterfs",
|
|
].includes(type);
|
|
}
|
|
|
|
export function aggregateMountedDiskUsage(
|
|
disks: readonly MountedDiskUsage[],
|
|
): AggregatedDiskUsage | null {
|
|
const capacityGroups = new Map<string, { used: number; total: number }>();
|
|
|
|
for (const disk of disks) {
|
|
if (!Number.isFinite(disk.used) || !Number.isFinite(disk.total)) continue;
|
|
if (disk.used < 0 || disk.total <= 0) continue;
|
|
const filesystemType = disk.filesystemType?.trim();
|
|
const hasFilesystemType = filesystemType && filesystemType !== "-";
|
|
if (hasFilesystemType
|
|
? isNetworkOrFuseFilesystemType(filesystemType)
|
|
: isNetworkOrFuseCapacityKey(disk.capacityKey)) continue;
|
|
const identity = disk.capacityKey?.trim() || `mount:${disk.mountPoint}`;
|
|
const existing = capacityGroups.get(identity);
|
|
capacityGroups.set(identity, {
|
|
used: Math.max(existing?.used ?? 0, disk.used),
|
|
total: Math.max(existing?.total ?? 0, disk.total),
|
|
});
|
|
}
|
|
|
|
let used = 0;
|
|
let total = 0;
|
|
for (const group of capacityGroups.values()) {
|
|
used += group.used;
|
|
total += group.total;
|
|
}
|
|
|
|
if (total <= 0) return null;
|
|
|
|
return {
|
|
used,
|
|
total,
|
|
percent: Math.max(0, Math.min(100, (used / total) * 100)),
|
|
};
|
|
}
|