MCPcopy Index your code
hub / github.com/devspace-sh/devspace / DownloadBinary

Method DownloadBinary

pkg/devspace/plugin/installer.go:27–66  ·  view source on GitHub ↗
(metadataPath, version, binaryPath, outFile string)

Source from the content-addressed store, hash-verified

25}
26
27func (i *installer) DownloadBinary(metadataPath, version, binaryPath, outFile string) error {
28 if isLocalReference(metadataPath) {
29 localPath := filepath.Join(filepath.Dir(metadataPath), binaryPath)
30 if isLocalReference(localPath) {
31 return copy.Copy(localPath, outFile)
32 } else if isLocalReference(binaryPath) {
33 return copy.Copy(binaryPath, outFile)
34 }
35
36 return i.downloadTo(binaryPath, outFile)
37 } else if isRemoteHTTPYAML(metadataPath) {
38 return i.downloadTo(binaryPath, outFile)
39 }
40
41 if strings.HasPrefix(binaryPath, "http://") || strings.HasPrefix(binaryPath, "https://") {
42 return i.downloadTo(binaryPath, outFile)
43 }
44
45 tempDir, err := os.MkdirTemp("", "")
46 if err != nil {
47 return err
48 }
49
50 defer os.RemoveAll(tempDir)
51 repo, err := git.NewGitCLIRepository(context.Background(), tempDir)
52 if err != nil {
53 return err
54 }
55
56 err = repo.Clone(context.Background(), git.CloneOptions{
57 URL: metadataPath,
58 Tag: version,
59 })
60 if err != nil {
61 return err
62 }
63 _ = repo.Pull(context.Background())
64
65 return copy.Copy(filepath.Join(tempDir, binaryPath), outFile)
66}
67
68func (i *installer) downloadTo(binaryPath, outFile string) error {
69 resp, err := http.Get(binaryPath)

Callers

nothing calls this directly

Calls 7

downloadToMethod · 0.95
CloneMethod · 0.95
PullMethod · 0.95
NewGitCLIRepositoryFunction · 0.92
isLocalReferenceFunction · 0.85
isRemoteHTTPYAMLFunction · 0.85
CopyMethod · 0.65

Tested by

no test coverage detected