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

Function tryReclaimBinaryLock

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

Source from the content-addressed store, hash-verified

272}
273
274function tryReclaimBinaryLock(lockPath, contenderToken) {
275 let reclaim = false;
276 const owner = readBinaryLockOwner(lockPath);
277 if (owner) {
278 reclaim = !processIsAlive(owner.pid);
279 } else {
280 try {
281 const age = Date.now() - fs.statSync(lockPath).mtimeMs;
282 reclaim = age >= WINDOWS_PAIR_OWNERLESS_STALE_MS;
283 } catch (_) {
284 return true; // The owner released it between observation and inspection.
285 }
286 }
287 if (!reclaim) return false;
288
289 const reclaimed = `${lockPath}.reclaimed-${contenderToken}`;
290 try {
291 fs.renameSync(lockPath, reclaimed);
292 } catch (err) {
293 if (err.code === 'ENOENT') return true;
294 return false;
295 }
296 fs.rmSync(reclaimed, { recursive: true, force: true });
297 return true;
298}
299
300function acquireWindowsBinaryLock(destDir) {
301 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