()
| 564 | } |
| 565 | |
| 566 | private readHolder(): LockHolder { |
| 567 | let content: string; |
| 568 | try { |
| 569 | content = fs.readFileSync(this.lockPath, 'utf-8').trim(); |
| 570 | } catch (err) { |
| 571 | // Unreadable is not proof the holder is gone: leave it to `codegraph unlock`. |
| 572 | return (err as NodeJS.ErrnoException).code === 'ENOENT' ? { state: 'free' } : { state: 'held' }; |
| 573 | } |
| 574 | if (content === '') { |
| 575 | let age: number; |
| 576 | try { |
| 577 | age = Date.now() - fs.statSync(this.lockPath).mtimeMs; |
| 578 | } catch { |
| 579 | return { state: 'free' }; |
| 580 | } |
| 581 | return age < EMPTY_LOCK_GRACE_MS ? { state: 'held' } : { state: 'stale' }; |
| 582 | } |
| 583 | const pid = parseInt(content, 10); |
| 584 | // Malformed: no process owns it. |
| 585 | if (!(pid > 0)) return { state: 'stale' }; |
| 586 | return this.isProcessAlive(pid) ? { state: 'held', pid } : { state: 'stale' }; |
| 587 | } |
| 588 | |
| 589 | /** |
| 590 | * Release the lock |
no test coverage detected