MCPcopy Create free account
hub / github.com/claude-code-best/claude-code / performVersionUpdate

Function performVersionUpdate

src/utils/nativeInstaller/installer.ts:438–485  ·  view source on GitHub ↗

* Performs the core update operation: download (if needed), install, and update symlink. * Returns whether a new install was performed (vs just updating symlink).

(
  version: string,
  forceReinstall: boolean,
)

Source from the content-addressed store, hash-verified

436 * Returns whether a new install was performed (vs just updating symlink).
437 */
438async function performVersionUpdate(
439 version: string,
440 forceReinstall: boolean,
441): Promise<boolean> {
442 const { stagingPath: baseStagingPath, installPath } =
443 await getVersionPaths(version)
444 const { executable: executablePath } = getBaseDirectories()
445
446 // For lockless updates, use a unique staging path to avoid conflicts between concurrent downloads
447 const stagingPath = isEnvTruthy(process.env.ENABLE_LOCKLESS_UPDATES)
448 ? `${baseStagingPath}.${process.pid}.${Date.now()}`
449 : baseStagingPath
450
451 // Only download if not already installed (or if force reinstall)
452 const needsInstall = !(await versionIsAvailable(version)) || forceReinstall
453 if (needsInstall) {
454 logForDebugging(
455 forceReinstall
456 ? `Force reinstalling native installer version ${version}`
457 : `Downloading native installer version ${version}`,
458 )
459 const downloadType = await downloadVersion(version, stagingPath)
460 await installVersion(stagingPath, installPath, downloadType)
461 } else {
462 logForDebugging(`Version ${version} already installed, updating symlink`)
463 }
464
465 // Create direct symlink from ~/.local/bin/claude to the version binary
466 await removeDirectoryIfEmpty(executablePath)
467 await updateSymlink(executablePath, installPath)
468
469 // Verify the executable was actually created/updated
470 if (!(await isPossibleClaudeBinary(executablePath))) {
471 let installPathExists = false
472 try {
473 await stat(installPath)
474 installPathExists = true
475 } catch {
476 // installPath doesn't exist
477 }
478 throw new Error(
479 `Failed to create executable at ${executablePath}. ` +
480 `Source file exists: ${installPathExists}. ` +
481 `Check write permissions to ${executablePath}.`,
482 )
483 }
484 return needsInstall
485}
486
487async function versionIsAvailable(version: string): Promise<boolean> {
488 const { installPath } = await getVersionPaths(version)

Callers 1

updateLatestFunction · 0.85

Calls 12

getVersionPathsFunction · 0.85
getBaseDirectoriesFunction · 0.85
versionIsAvailableFunction · 0.85
downloadVersionFunction · 0.85
installVersionFunction · 0.85
removeDirectoryIfEmptyFunction · 0.85
updateSymlinkFunction · 0.85
isPossibleClaudeBinaryFunction · 0.85
statFunction · 0.85
nowMethod · 0.80
isEnvTruthyFunction · 0.50
logForDebuggingFunction · 0.50

Tested by

no test coverage detected