(lockPath: string, logPrefix: string)
| 74 | } |
| 75 | |
| 76 | function parseLock(lockPath: string, logPrefix: string): ProcessLockMetadata | null { |
| 77 | try { |
| 78 | const parsed = JSON.parse(readFileSync(lockPath, 'utf-8')); |
| 79 | if (parsed && typeof parsed === 'object' && isValidLockPid((parsed as { pid?: unknown }).pid)) { |
| 80 | return parsed as ProcessLockMetadata; |
| 81 | } |
| 82 | console.warn(`${logPrefix} Corrupt lock file at ${lockPath} — replacing`); |
| 83 | return null; |
| 84 | } catch { |
| 85 | console.warn(`${logPrefix} Corrupt lock file at ${lockPath} — replacing`); |
| 86 | return null; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | export function acquireProcessLock(opts: { |
| 91 | lockName: LockName; |
no test coverage detected