(raw: string)
| 182 | * we treat such a lockfile as "process is unknown version, refuse to share." |
| 183 | */ |
| 184 | export function decodeLockInfo(raw: string): DaemonLockInfo | null { |
| 185 | const trimmed = raw.trim(); |
| 186 | if (!trimmed) return null; |
| 187 | try { |
| 188 | const parsed = JSON.parse(trimmed); |
| 189 | if ( |
| 190 | parsed && |
| 191 | typeof parsed.pid === 'number' && |
| 192 | typeof parsed.version === 'string' && |
| 193 | typeof parsed.socketPath === 'string' && |
| 194 | typeof parsed.startedAt === 'number' |
| 195 | ) { |
| 196 | return parsed as DaemonLockInfo; |
| 197 | } |
| 198 | } catch { |
| 199 | // Fall through to legacy plain-pid handling. |
| 200 | } |
| 201 | if (!/^[1-9]\d*$/.test(trimmed)) return null; |
| 202 | const pid = Number(trimmed); |
| 203 | if (Number.isSafeInteger(pid)) { |
| 204 | return { pid, version: 'unknown', socketPath: '', startedAt: 0 }; |
| 205 | } |
| 206 | return null; |
| 207 | } |
no test coverage detected