MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / acquireWindowsBinaryLock

Function acquireWindowsBinaryLock

pkg/npm/install.js:438–465  ·  view source on GitHub ↗
(destDir)

Source from the content-addressed store, hash-verified

436}
437
438function 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
467function releaseWindowsBinaryLock(lock) {
468 const owner = readBinaryLockOwner(lock.lockPath);

Callers 1

Calls 2

tryReclaimBinaryLockFunction · 0.85
sleepSyncFunction · 0.85

Tested by

no test coverage detected