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

Function tryReclaimBinaryLock

pkg/npm/install.js:412–436  ·  view source on GitHub ↗
(lockPath, contenderToken)

Source from the content-addressed store, hash-verified

410}
411
412function tryReclaimBinaryLock(lockPath, contenderToken) {
413 let reclaim = false;
414 const owner = readBinaryLockOwner(lockPath);
415 if (owner) {
416 reclaim = !processIsAlive(owner.pid);
417 } else {
418 try {
419 const age = Date.now() - fs.statSync(lockPath).mtimeMs;
420 reclaim = age >= WINDOWS_PAIR_OWNERLESS_STALE_MS;
421 } catch (_) {
422 return true; // The owner released it between observation and inspection.
423 }
424 }
425 if (!reclaim) return false;
426
427 const reclaimed = `${lockPath}.reclaimed-${contenderToken}`;
428 try {
429 fs.renameSync(lockPath, reclaimed);
430 } catch (err) {
431 if (err.code === 'ENOENT') return true;
432 return false;
433 }
434 fs.rmSync(reclaimed, { recursive: true, force: true });
435 return true;
436}
437
438function acquireWindowsBinaryLock(destDir) {
439 const lockPath = path.join(destDir, WINDOWS_PAIR_LOCK_NAME);

Callers 1

acquireWindowsBinaryLockFunction · 0.85

Calls 2

readBinaryLockOwnerFunction · 0.85
processIsAliveFunction · 0.85

Tested by

no test coverage detected