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

Function tryAcquireGuard

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

Source from the content-addressed store, hash-verified

150}
151
152async function tryAcquireGuard(
153 lockDir: string,
154 purpose: string,
155 leaseMs: number,
156 now: number,
157): Promise<AcquiredFsLock | null> {
158 const guardDir = guardDirForLockDir(lockDir);
159 const guardOwner: FsLockOwner = {
160 token: randomUUID(),
161 pid: process.pid,
162 purpose: `${purpose}:guard`,
163 acquiredAtMs: now,
164 expiresAtMs: now + leaseMs,
165 };
166
167 try {
168 return await createLock(guardDir, guardOwner);
169 } catch (error) {
170 if ((error as NodeJS.ErrnoException).code !== 'EEXIST') {
171 return null;
172 }
173 const recovered = await tryRecoverExpiredLockDir(guardDir, guardOwner.purpose, now, leaseMs);
174 if (!recovered) {
175 return null;
176 }
177 try {
178 return await createLock(guardDir, guardOwner);
179 } catch {
180 return null;
181 }
182 }
183}
184
185export async function tryAcquireFsLock(
186 options: TryAcquireFsLockOptions,

Callers 1

tryAcquireFsLockFunction · 0.70

Calls 3

guardDirForLockDirFunction · 0.90
createLockFunction · 0.70
tryRecoverExpiredLockDirFunction · 0.70

Tested by

no test coverage detected