MCPcopy Create free account
hub / github.com/codehamr/codehamr / fetchHash

Function fetchHash

internal/update/update.go:257–288  ·  view source on GitHub ↗

fetchHash downloads codehamr_checksums.txt and returns the hash for asset. The manifest is one line per asset, " "; we match the last field so a future prefix tweak still works. A scanner read error is surfaced, not dropped as "", nil: Apply treats "no entry" as a fatal misma

(ctx context.Context, asset string)

Source from the content-addressed store, hash-verified

255// entry" as a fatal mismatch, so silently turning a network glitch into "asset
256// doesn't exist" would be a confusing error.
257func fetchHash(ctx context.Context, asset string) (string, error) {
258 req, err := http.NewRequestWithContext(ctx, "GET", checksumsURL, nil)
259 if err != nil {
260 return "", err
261 }
262 resp, err := (&http.Client{Timeout: fetchTimeout}).Do(req)
263 if err != nil {
264 return "", err
265 }
266 defer resp.Body.Close()
267 if resp.StatusCode != http.StatusOK {
268 return "", fmt.Errorf("non-200: %d", resp.StatusCode)
269 }
270 sc := bufio.NewScanner(resp.Body)
271 for sc.Scan() {
272 line := strings.TrimSpace(sc.Text())
273 if line == "" {
274 continue
275 }
276 fields := strings.Fields(line)
277 if len(fields) < 2 {
278 continue
279 }
280 if fields[len(fields)-1] == asset {
281 return fields[0], nil
282 }
283 }
284 if err := sc.Err(); err != nil {
285 return "", err
286 }
287 return "", nil
288}

Callers 3

CheckFunction · 0.85
ApplyFunction · 0.85

Calls

no outgoing calls

Tested by 1