MCPcopy Index your code
hub / github.com/getsentry/XcodeBuildMCP / tryAcquireGuard

Function tryAcquireGuard

src/utils/fs-lock-sync.ts:127–157  ·  view source on GitHub ↗
(
  lockDir: string,
  purpose: string,
  leaseMs: number,
  now: number,
)

Source from the content-addressed store, hash-verified

125}
126
127function tryAcquireGuard(
128 lockDir: string,
129 purpose: string,
130 leaseMs: number,
131 now: number,
132): AcquiredFsLockSync | null {
133 const guardDir = guardDirForLockDir(lockDir);
134 const guardOwner: FsLockOwner = {
135 token: randomUUID(),
136 pid: process.pid,
137 purpose: `${purpose}:guard`,
138 acquiredAtMs: now,
139 expiresAtMs: now + leaseMs,
140 };
141
142 try {
143 return createLock(guardDir, guardOwner);
144 } catch (error) {
145 if ((error as NodeJS.ErrnoException).code !== 'EEXIST') {
146 return null;
147 }
148 if (!tryRecoverExpiredLockDir(guardDir, guardOwner.purpose, now, leaseMs)) {
149 return null;
150 }
151 try {
152 return createLock(guardDir, guardOwner);
153 } catch {
154 return null;
155 }
156 }
157}
158
159export function tryAcquireFsLockSync(
160 options: TryAcquireFsLockSyncOptions,

Callers 1

tryAcquireFsLockSyncFunction · 0.70

Calls 3

guardDirForLockDirFunction · 0.90
createLockFunction · 0.70
tryRecoverExpiredLockDirFunction · 0.70

Tested by

no test coverage detected