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

Function downloadSyncHelper

pkg/devspace/services/inject/inject.go:166–223  ·  view source on GitHub ↗
(ctx context.Context, helperName, syncBinaryFolder, version string, log logpkg.Logger)

Source from the content-addressed store, hash-verified

164}
165
166func downloadSyncHelper(ctx context.Context, helperName, syncBinaryFolder, version string, log logpkg.Logger) error {
167 filepath := filepath.Join(syncBinaryFolder, helperName)
168
169 // Check if file exists
170 _, err := os.Stat(filepath)
171 if err == nil {
172 // make sure the sha is correct, but skip for latest because that is development
173 if version == "latest" {
174 log.Debugf("Use development devspacehelper found at %s", filepath)
175 return nil
176 }
177
178 // download sha256 html
179 url := fmt.Sprintf("https://github.com/devspace-sh/devspace/releases/download/%s/%s.sha256", version, helperName)
180 req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
181 if err != nil {
182 return nil
183 }
184 resp, err := http.DefaultClient.Do(req)
185 if err != nil {
186 log.Warnf("Couldn't retrieve helper sha256: %v", err)
187 return nil
188 }
189
190 shaHash, err := io.ReadAll(resp.Body)
191 if err != nil {
192 log.Warnf("Couldn't read helper sha256 request: %v", err)
193 return nil
194 }
195
196 // hash the local binary
197 fileHash, err := hash.File(filepath)
198 if err != nil {
199 log.Warnf("Couldn't hash local helper binary: %v", err)
200 return nil
201 }
202
203 // the file is correct we skip downloading
204 if fileHash == strings.Split(string(shaHash), " ")[0] {
205 log.Debugf("Use local devspacehelper found at %s", filepath)
206 return nil
207 }
208
209 // remove the old binary
210 err = os.Remove(filepath)
211 if err != nil {
212 return errors.Wrap(err, "remove corrupt helper binary")
213 }
214 }
215
216 // Make sync binary
217 log.Infof("Couldn't find %s, will try to download it now", helperName)
218 err = os.MkdirAll(syncBinaryFolder, 0755)
219 if err != nil {
220 return errors.Wrap(err, "mkdir helper binary folder")
221 }
222 return downloadFile(version, filepath, helperName)
223}

Callers 1

InjectDevSpaceHelperFunction · 0.85

Calls 6

FileFunction · 0.92
downloadFileFunction · 0.70
RemoveMethod · 0.65
DebugfMethod · 0.45
WarnfMethod · 0.45
InfofMethod · 0.45

Tested by

no test coverage detected