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

Function acquireLockViaExclusiveOpen

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

Source from the content-addressed store, hash-verified

904 * window between create and write. Exported for testing.
905 */
906export function acquireLockViaExclusiveOpen(pidPath: string, info: DaemonLockInfo): boolean {
907 let fd: number;
908 try {
909 fd = fs.openSync(pidPath, 'wx', 0o600); // O_CREAT | O_EXCL | O_WRONLY
910 } catch (err: unknown) {
911 if ((err as NodeJS.ErrnoException).code === 'EEXIST') return false;
912 throw err;
913 }
914 try {
915 fs.writeSync(fd, encodeLockInfo(info));
916 } finally {
917 fs.closeSync(fd);
918 }
919 return true;
920}
921
922/**
923 * Remove a stale pidfile. Re-reads the file immediately before unlinking so a

Callers 2

tryAcquireDaemonLockFunction · 0.85

Calls 2

encodeLockInfoFunction · 0.90
openSyncMethod · 0.45

Tested by

no test coverage detected