* Parse a lock file's contents. Understands both the current JSON payload and * the legacy plain-integer PID format written by older teamai versions, so an * on-disk lock from a previous install is still evaluated for staleness rather * than treated as un-owned garbage.
(content: string)
| 138 | * than treated as un-owned garbage. |
| 139 | */ |
| 140 | function parseLockContent(content: string): { pid: number; owner?: string } | null { |
| 141 | const trimmed = content.trim(); |
| 142 | if (!trimmed) return null; |
| 143 | try { |
| 144 | const parsed = JSON.parse(trimmed) as Partial<LockPayload>; |
| 145 | if (typeof parsed.pid === 'number' && !isNaN(parsed.pid)) { |
| 146 | return { pid: parsed.pid, owner: typeof parsed.owner === 'string' ? parsed.owner : undefined }; |
| 147 | } |
| 148 | return null; |
| 149 | } catch { |
| 150 | // Legacy format: the file held only the bare PID as a string. |
| 151 | const pid = parseInt(trimmed, 10); |
| 152 | return isNaN(pid) ? null : { pid }; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Inspect the lock at `resolved` and report whether it is stale — its owning |
no outgoing calls
no test coverage detected