* Acquire the lock. Throws if the lock is held by another live process. * * A free lock costs one create. A stale one, whose PID is dead or missing, * is replaced only by the process holding ` .break` (itself a * FileLock), after reading it again there (#2979). Before, two processes
()
| 510 | * write as the only writer. |
| 511 | */ |
| 512 | acquire(): void { |
| 513 | const refusal = this.tryAcquire(0); |
| 514 | if (refusal) { |
| 515 | const who = refusal.state === 'held' && refusal.pid !== undefined ? ` (PID ${refusal.pid})` : ''; |
| 516 | throw new Error( |
| 517 | `CodeGraph database is locked by another process${who}. ` + |
| 518 | `If this is stale, run 'codegraph unlock' or delete ${this.lockPath}` |
| 519 | ); |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | /** Null once the lock is ours; otherwise what kept us out. */ |
| 524 | private tryAcquire(depth: number): LockHolder | null { |
no test coverage detected