MCPcopy Index your code
hub / github.com/codeaashu/claude-code / cleanupStaleIdeLockfiles

Function cleanupStaleIdeLockfiles

src/utils/ide.ts:522–581  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

520 * - Removes lockfiles for ports that are not responding
521 */
522export async function cleanupStaleIdeLockfiles(): Promise<void> {
523 try {
524 const lockfiles = await getSortedIdeLockfiles()
525
526 for (const lockfilePath of lockfiles) {
527 const lockfileInfo = await readIdeLockfile(lockfilePath)
528
529 if (!lockfileInfo) {
530 // If we can't read the lockfile, delete it
531 try {
532 await getFsImplementation().unlink(lockfilePath)
533 } catch (error) {
534 logError(error as Error)
535 }
536 continue
537 }
538
539 const host = await detectHostIP(
540 lockfileInfo.runningInWindows,
541 lockfileInfo.port,
542 )
543
544 let shouldDelete = false
545
546 if (lockfileInfo.pid) {
547 // Check if the process is still running
548 if (!isProcessRunning(lockfileInfo.pid)) {
549 if (getPlatform() !== 'wsl') {
550 shouldDelete = true
551 } else {
552 // The process id may not be reliable in wsl, so also check the connection
553 const isResponding = await checkIdeConnection(
554 host,
555 lockfileInfo.port,
556 )
557 if (!isResponding) {
558 shouldDelete = true
559 }
560 }
561 }
562 } else {
563 // No PID, check if the URL is responding
564 const isResponding = await checkIdeConnection(host, lockfileInfo.port)
565 if (!isResponding) {
566 shouldDelete = true
567 }
568 }
569
570 if (shouldDelete) {
571 try {
572 await getFsImplementation().unlink(lockfilePath)
573 } catch (error) {
574 logError(error as Error)
575 }
576 }
577 }
578 } catch (error) {
579 logError(error as Error)

Callers 1

findAvailableIDEFunction · 0.85

Calls 7

getSortedIdeLockfilesFunction · 0.85
readIdeLockfileFunction · 0.85
getFsImplementationFunction · 0.85
getPlatformFunction · 0.85
checkIdeConnectionFunction · 0.85
logErrorFunction · 0.70
isProcessRunningFunction · 0.70

Tested by

no test coverage detected