MCPcopy Index your code
hub / github.com/callstack/agent-device / acquireSwiftCacheLock

Function acquireSwiftCacheLock

src/utils/swift-cache.ts:125–160  ·  view source on GitHub ↗
(
  lockDir: string,
  executablePath: string,
  timeoutMs: number,
)

Source from the content-addressed store, hash-verified

123}
124
125async function acquireSwiftCacheLock(
126 lockDir: string,
127 executablePath: string,
128 timeoutMs: number,
129): Promise<(() => Promise<void>) | null> {
130 if (isExecutableFile(executablePath)) {
131 return null;
132 }
133 try {
134 return await acquireProcessLock({
135 lockDirPath: lockDir,
136 owner: {
137 pid: process.pid,
138 startTime: readProcessStartTime(process.pid),
139 acquiredAtMs: Date.now(),
140 },
141 timeoutMs,
142 pollMs: LOCK_RETRY_DELAY_MS,
143 ownerGraceMs: timeoutMs,
144 description: `Swift cache lock: ${lockDir} (${timeoutMs}ms)`,
145 });
146 } catch (error) {
147 if (
148 error instanceof AppError &&
149 error.message.startsWith('Timed out waiting for Swift cache lock:')
150 ) {
151 throw new AppError('COMMAND_FAILED', error.message, {
152 ...error.details,
153 lockDir,
154 timeoutMs,
155 hint: `Another agent-device process may still be compiling this Swift helper. Retry shortly; if no agent-device process is active, remove "${lockDir}" and retry.`,
156 });
157 }
158 throw error;
159 }
160}
161
162function isExecutableFile(filePath: string): boolean {
163 try {

Callers 1

ensureSwiftExecutableFunction · 0.85

Calls 4

acquireProcessLockFunction · 0.90
readProcessStartTimeFunction · 0.90
isExecutableFileFunction · 0.85
startsWithMethod · 0.80

Tested by

no test coverage detected