MCPcopy Create free account
hub / github.com/bracesdev/errtrace / binaryVersion

Function binaryVersion

cmd/errtrace/toolexec.go:269–287  ·  view source on GitHub ↗

binaryVersion returns a string that uniquely identifies the binary. We prefer to use the VCS info embedded in the build if possible falling back to the MD5 of the binary.

()

Source from the content-addressed store, hash-verified

267// We prefer to use the VCS info embedded in the build if possible
268// falling back to the MD5 of the binary.
269func binaryVersion() (string, error) {
270 sha, ok := readBuildSHA()
271 if ok {
272 return sha, nil
273 }
274
275 exe, err := os.Executable()
276 if err != nil {
277 return "", errtrace.Wrap(err)
278 }
279
280 contents, err := os.ReadFile(exe)
281 if err != nil {
282 return "", errtrace.Wrap(err)
283 }
284
285 binaryHash := md5.Sum(contents)
286 return hex.EncodeToString(binaryHash[:]), nil
287}
288
289// readBuildSHA returns the VCS SHA, if it's from an unmodified VCS state.
290func readBuildSHA() (_ string, ok bool) {

Callers 1

toolExecVersionMethod · 0.85

Calls 2

WrapFunction · 0.92
readBuildSHAFunction · 0.85

Tested by

no test coverage detected