MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / readHolder

Method readHolder

src/utils.ts:566–587  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 1

tryAcquireMethod · 0.95

Calls 1

isProcessAliveMethod · 0.95

Tested by

no test coverage detected