MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / detectFreeDisk

Function detectFreeDisk

src/setup/hardware-profile.ts:140–163  ·  view source on GitHub ↗
(osKind: HardwareProfile['os'])

Source from the content-addressed store, hash-verified

138// ── Disk free ────────────────────────────────────────────────────────────────
139
140function detectFreeDisk(osKind: HardwareProfile['os']): number | null {
141 if (osKind === 'macos' || osKind === 'linux') {
142 // `df -k .` is portable across both. Take the "Available" column.
143 const r = tryRun('df', ['-k', os.homedir()], 2000);
144 if (r && r.exitCode === 0) {
145 const lines = r.stdout.trim().split('\n');
146 const data = lines[lines.length - 1] ?? '';
147 const cols = data.split(/\s+/);
148 // df output: Filesystem 1024-blocks Used Available Capacity Mounted
149 const availKb = parseInt(cols[3] ?? '0', 10);
150 if (availKb > 0) return Math.round(availKb / 1024 / 1024);
151 }
152 }
153 if (osKind === 'windows') {
154 // PowerShell one-liner — only attempted if powershell is on PATH
155 const r = tryRun('powershell', ['-NoProfile', '-Command',
156 '(Get-PSDrive C).Free / 1GB'], 3000);
157 if (r && r.exitCode === 0) {
158 const n = parseFloat(r.stdout.trim());
159 if (!isNaN(n)) return Math.round(n);
160 }
161 }
162 return null;
163}
164
165// ── Tier ─────────────────────────────────────────────────────────────────────
166

Callers 1

detectHardwareFunction · 0.85

Calls 1

tryRunFunction · 0.85

Tested by

no test coverage detected