(destDir)
| 298 | } |
| 299 | |
| 300 | function acquireWindowsBinaryLock(destDir) { |
| 301 | const lockPath = path.join(destDir, WINDOWS_PAIR_LOCK_NAME); |
| 302 | const token = crypto.randomBytes(16).toString('hex'); |
| 303 | const deadline = Date.now() + WINDOWS_PAIR_LOCK_WAIT_MS; |
| 304 | for (;;) { |
| 305 | try { |
| 306 | fs.mkdirSync(lockPath, { mode: 0o700 }); |
| 307 | try { |
| 308 | fs.writeFileSync( |
| 309 | path.join(lockPath, 'owner.json'), |
| 310 | `${JSON.stringify({ pid: process.pid, token })}\n`, |
| 311 | { encoding: 'utf8', flag: 'wx', mode: 0o600 }, |
| 312 | ); |
| 313 | } catch (err) { |
| 314 | fs.rmSync(lockPath, { recursive: true, force: true }); |
| 315 | throw err; |
| 316 | } |
| 317 | return { lockPath, token }; |
| 318 | } catch (err) { |
| 319 | if (err.code !== 'EEXIST') throw err; |
| 320 | if (tryReclaimBinaryLock(lockPath, token)) continue; |
| 321 | if (Date.now() >= deadline) { |
| 322 | throw new Error('timed out waiting for Windows package-cache publication lock'); |
| 323 | } |
| 324 | sleepSync(WINDOWS_PAIR_LOCK_POLL_MS); |
| 325 | } |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | function releaseWindowsBinaryLock(lock) { |
| 330 | const owner = readBinaryLockOwner(lock.lockPath); |
no test coverage detected