(destDir)
| 436 | } |
| 437 | |
| 438 | function acquireWindowsBinaryLock(destDir) { |
| 439 | const lockPath = path.join(destDir, WINDOWS_PAIR_LOCK_NAME); |
| 440 | const token = crypto.randomBytes(16).toString('hex'); |
| 441 | const deadline = Date.now() + WINDOWS_PAIR_LOCK_WAIT_MS; |
| 442 | for (;;) { |
| 443 | try { |
| 444 | fs.mkdirSync(lockPath, { mode: 0o700 }); |
| 445 | try { |
| 446 | fs.writeFileSync( |
| 447 | path.join(lockPath, 'owner.json'), |
| 448 | `${JSON.stringify({ pid: process.pid, token })}\n`, |
| 449 | { encoding: 'utf8', flag: 'wx', mode: 0o600 }, |
| 450 | ); |
| 451 | } catch (err) { |
| 452 | fs.rmSync(lockPath, { recursive: true, force: true }); |
| 453 | throw err; |
| 454 | } |
| 455 | return { lockPath, token }; |
| 456 | } catch (err) { |
| 457 | if (err.code !== 'EEXIST') throw err; |
| 458 | if (tryReclaimBinaryLock(lockPath, token)) continue; |
| 459 | if (Date.now() >= deadline) { |
| 460 | throw new Error('timed out waiting for Windows package-cache publication lock'); |
| 461 | } |
| 462 | sleepSync(WINDOWS_PAIR_LOCK_POLL_MS); |
| 463 | } |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | function releaseWindowsBinaryLock(lock) { |
| 468 | const owner = readBinaryLockOwner(lock.lockPath); |
no test coverage detected