( lockDir: string, executablePath: string, timeoutMs: number, )
| 123 | } |
| 124 | |
| 125 | async 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 | |
| 162 | function isExecutableFile(filePath: string): boolean { |
| 163 | try { |
no test coverage detected