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

Function download

pkg/go/cmd/codebase-memory-mcp/main.go:352–447  ·  view source on GitHub ↗
(dest string)

Source from the content-addressed store, hash-verified

350}
351
352func download(dest string) error {
353 platform := goos()
354 arch := goarch()
355 ext := "tar.gz"
356 if platform == "windows" {
357 ext = "zip"
358 }
359
360 portable := ""
361 if platform == "linux" {
362 portable = "-portable"
363 }
364 archive := fmt.Sprintf(
365 "codebase-memory-mcp-%s-%s%s.%s",
366 platform, arch, portable, ext,
367 )
368 base, loopback, err := downloadBase(os.Getenv("CBM_DOWNLOAD_URL"))
369 if err != nil {
370 return err
371 }
372 url := base + "/" + archive
373 checksumURL := base + "/checksums.txt"
374
375 fmt.Fprintf(os.Stderr, "codebase-memory-mcp: downloading v%s for %s/%s...\n", installVersion, platform, arch)
376
377 tmp, err := os.MkdirTemp("", "cbm-install-*")
378 if err != nil {
379 return err
380 }
381 defer os.RemoveAll(tmp)
382
383 archivePath := filepath.Join(tmp, "cbm."+ext)
384 if err := httpGet(url, archivePath, loopback); err != nil {
385 return fmt.Errorf("download failed: %w", err)
386 }
387
388 // A release binary is executable input, so checksum verification is a
389 // mandatory precondition rather than a best-effort warning.
390 checksums, err := fetchChecksums(checksumURL, loopback)
391 if err != nil {
392 return fmt.Errorf("checksum manifest unavailable: %w", err)
393 }
394 expected, ok := checksums[archive]
395 if !ok {
396 return fmt.Errorf("checksum manifest has no entry for %s", archive)
397 }
398 if err := verifyChecksum(archivePath, expected); err != nil {
399 return err
400 }
401
402 binName := binaryNameForOS(platform)
403 archiveNames := archiveNamesForOS(platform, binName)
404 extractNames := []string{binName}
405 var runtimeNames []string
406
407 if ext == "tar.gz" {
408 runtimeNames, err = extractTarGz(
409 archivePath, tmp, archiveNames, extractNames,

Callers 1

ensureBinaryFunction · 0.70

Calls 12

goosFunction · 0.85
goarchFunction · 0.85
downloadBaseFunction · 0.85
httpGetFunction · 0.85
fetchChecksumsFunction · 0.85
binaryNameForOSFunction · 0.85
archiveNamesForOSFunction · 0.85
extractTarGzFunction · 0.85
extractZipFunction · 0.85
verifyChecksumFunction · 0.70
verifyCandidateFunction · 0.70

Tested by

no test coverage detected