mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-17 04:50:52 +00:00
* fix(system): aggregate mounted disk capacity * fix(system): dedupe disk capacity totals * fix(system): dedupe shared disk capacity * fix(system): measure shared APFS usage * fix(system): include overfull disks in totals * fix(system): exclude loop-backed disk images
45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
export interface MountedDiskUsage {
|
|
capacityKey?: string;
|
|
mountPoint: string;
|
|
used: number;
|
|
total: number;
|
|
}
|
|
|
|
export interface AggregatedDiskUsage {
|
|
used: number;
|
|
total: number;
|
|
percent: number;
|
|
}
|
|
|
|
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 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)),
|
|
};
|
|
}
|