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

Function Check

internal/update/update.go:56–73  ·  view source on GitHub ↗

Check reports whether the local binary's sha256 differs from the remote asset's recorded hash. ctx propagates a startup Ctrl+C into the HTTP request. Returns false on any failure; see package doc.

(ctx context.Context, execPath string)

Source from the content-addressed store, hash-verified

54// asset's recorded hash. ctx bounds the HTTP request (the caller's update
55// budget). Returns false on any failure; see package doc.
56func Check(ctx context.Context, execPath string) bool {
57 if os.Getenv("CODEHAMR_NO_UPDATE_CHECK") == "1" {
58 return false
59 }
60 asset, ok := assetName(runtime.GOOS, runtime.GOARCH)
61 if !ok {
62 return false
63 }
64 local, err := hashFile(execPath)
65 if err != nil {
66 return false
67 }
68 remote, err := fetchHash(ctx, asset)
69 if err != nil || remote == "" {
70 return false
71 }
72 return !strings.EqualFold(local, remote)
73}
74
75// assetName mirrors the name_template in .goreleaser.yaml. Every goos goreleaser
76// builds for must have a case here; a missing one silently locks that

Callers 4

maybeSelfUpdateFunction · 0.92
TestCheckReportsUpToDateFunction · 0.85
TestCheckReportsStaleFunction · 0.85

Calls 3

assetNameFunction · 0.85
hashFileFunction · 0.85
fetchHashFunction · 0.85

Tested by 3

TestCheckReportsUpToDateFunction · 0.68
TestCheckReportsStaleFunction · 0.68