(opts: { lockName: LockName; lockDir: string })
| 312 | } |
| 313 | |
| 314 | export function releaseProcessLock(opts: { lockName: LockName; lockDir: string }): void { |
| 315 | const { lockName, lockDir } = opts; |
| 316 | const logPrefix = `[${lockName}-lock]`; |
| 317 | const lockPath = lockFilePath(lockDir, lockName); |
| 318 | if (!dropActiveLockRef(lockPath)) { |
| 319 | return; |
| 320 | } |
| 321 | if (!existsSync(lockPath)) return; |
| 322 | try { |
| 323 | const parsed = JSON.parse(readFileSync(lockPath, 'utf-8')); |
| 324 | if (!parsed || typeof parsed !== 'object' || typeof parsed.pid !== 'number') return; |
| 325 | if (parsed.pid !== process.pid) return; |
| 326 | if (typeof parsed.hostname === 'string' && parsed.hostname !== hostname()) return; |
| 327 | unlinkSync(lockPath); |
| 328 | } catch (err) { |
| 329 | console.warn( |
| 330 | `${logPrefix} Failed to release ${lockPath}: ${err instanceof Error ? err.message : String(err)}`, |
| 331 | ); |
| 332 | } |
| 333 | } |
no test coverage detected