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

Function acquireLockViaExclusiveOpen

src/mcp/daemon.ts:615–629  ·  view source on GitHub ↗
(pidPath: string, info: DaemonLockInfo)

Source from the content-addressed store, hash-verified

613 * window between create and write. Exported for testing.
614 */
615export function acquireLockViaExclusiveOpen(pidPath: string, info: DaemonLockInfo): boolean {
616 let fd: number;
617 try {
618 fd = fs.openSync(pidPath, 'wx', 0o600); // O_CREAT | O_EXCL | O_WRONLY
619 } catch (err: unknown) {
620 if ((err as NodeJS.ErrnoException).code === 'EEXIST') return false;
621 throw err;
622 }
623 try {
624 fs.writeSync(fd, encodeLockInfo(info));
625 } finally {
626 fs.closeSync(fd);
627 }
628 return true;
629}
630
631/**
632 * Remove a stale pidfile, but only if it still names a dead process. Re-reads

Callers 2

tryAcquireDaemonLockFunction · 0.85

Calls 2

encodeLockInfoFunction · 0.90
openSyncMethod · 0.80

Tested by

no test coverage detected