MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / buildWindowsUpgradeScript

Function buildWindowsUpgradeScript

src/upgrade/index.ts:780–814  ·  view source on GitHub ↗
(bundleRoot: string, version: string, arch: string)

Source from the content-addressed store, hash-verified

778
779/** Build the in-place Windows upgrade script (exported for unit-testing). */
780export function buildWindowsUpgradeScript(bundleRoot: string, version: string, arch: string): string {
781 const target = `win32-${arch}`;
782 const url = `https://github.com/${REPO}/releases/download/${version}/codegraph-${target}.zip`;
783 // Synchronous, no detached helper (which dies under SSH/job objects and has
784 // worse UX). The bundle is unpacked into a sibling of current\ — the same
785 // volume, so the swap is renames, never a half-finished copy — and nothing
786 // in current\ changes until it is fully unpacked. The running process keeps
787 // its renamed node.exe mapped; the NEXT `codegraph` invocation uses the new
788 // one. Exit codes: 0 installed, 1 failed with the install unchanged,
789 // WINDOWS_UPGRADE_DAMAGED when the rollback could not restore every file.
790 return [
791 `$ErrorActionPreference='Stop'`,
792 WINDOWS_SWAP_FUNCTION,
793 `$dest=${psQuote(bundleRoot)}`,
794 `$url=${psQuote(url)}`,
795 `$tmp=Join-Path $env:TEMP ('cg-up-'+[guid]::NewGuid().ToString('N'))`,
796 `$stage=Join-Path (Split-Path -Parent $dest) ('.staging-'+[guid]::NewGuid().ToString('N').Substring(0,8))`,
797 `$code=0`,
798 `try {`,
799 ` Write-Host "Downloading $url"`,
800 ` New-Item -ItemType Directory -Force -Path $tmp | Out-Null`,
801 ` $zip=Join-Path $tmp 'cg.zip'`,
802 ` Invoke-WebRequest -Uri $url -OutFile $zip`,
803 ` Expand-Archive -Path $zip -DestinationPath $stage -Force`,
804 ` $inner=Join-Path $stage 'codegraph-${target}'`,
805 ` Install-CodeGraphFiles $(if(Test-Path $inner){$inner}else{$stage}) $dest`,
806 ` Write-Host "Installed CodeGraph ${version} to $dest"`,
807 `} catch {`,
808 ` [Console]::Error.WriteLine($_.Exception.Message)`,
809 ` $code=if($_.Exception.Data['codegraphDamaged']){${WINDOWS_UPGRADE_DAMAGED}}else{1}`,
810 `}`,
811 `Remove-Item -LiteralPath $stage,$tmp -Recurse -Force -ErrorAction SilentlyContinue`,
812 `exit $code`,
813 ].join('\n');
814}
815
816function upgradeWindowsBundle(
817 method: Extract<InstallMethod, { kind: 'bundle' }>,

Callers 3

upgrade.test.tsFile · 0.90
scriptFunction · 0.90
upgradeWindowsBundleFunction · 0.85

Calls 2

psQuoteFunction · 0.85
joinMethod · 0.45

Tested by 1

scriptFunction · 0.72