(osKind: HardwareProfile['os'])
| 138 | // ── Disk free ──────────────────────────────────────────────────────────────── |
| 139 | |
| 140 | function 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 |
no test coverage detected