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

Method create

src/utils.ts:569–589  ·  view source on GitHub ↗

* Create the lock file with our PID already in it, so no reader ever finds * it empty: write a private file, then hard-link it into place, which fails * if the lock exists. Where hard links are missing, fall back to an * exclusive create, whose PID lands a moment later (see * EMPTY_LOCK_

()

Source from the content-addressed store, hash-verified

567 * EMPTY_LOCK_GRACE_MS). False when the lock already exists.
568 */
569 private create(): boolean {
570 const pid = String(process.pid);
571 const tmp = `${this.lockPath}.${process.pid}.${threadId}.tmp`;
572 try {
573 fs.writeFileSync(tmp, pid);
574 fs.linkSync(tmp, this.lockPath);
575 return true;
576 } catch (err) {
577 if ((err as NodeJS.ErrnoException).code === 'EEXIST') return false;
578 // No hard links here (or no private file): create in place instead.
579 } finally {
580 try { fs.unlinkSync(tmp); } catch { /* never written */ }
581 }
582 try {
583 fs.writeFileSync(this.lockPath, pid, { flag: 'wx' });
584 return true;
585 } catch (err) {
586 if ((err as NodeJS.ErrnoException).code === 'EEXIST') return false;
587 throw err;
588 }
589 }
590
591 private readHolder(): LockHolder {
592 let content: string;

Callers 1

tryAcquireMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected