Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print sha256 of execuatble in the build details. #3828

Merged
merged 2 commits into from
Aug 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion x/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
package x

import (
"crypto/sha256"
"fmt"
"io"
"os"
"runtime"
"strings"

Expand Down Expand Up @@ -72,6 +75,7 @@ func BuildDetails() string {
}
return fmt.Sprintf(`
Dgraph version : %v
Dgraph SHA-256 : %x
Commit SHA-1 : %v
Commit timestamp : %v
Branch : %v
Expand All @@ -85,7 +89,8 @@ To say hi to the community , visit https://dgraph.slack.com.
Copyright 2015-2018 Dgraph Labs, Inc.

`,
dgraphVersion, lastCommitSHA, lastCommitTime, gitBranch, runtime.Version(), licenseInfo)
dgraphVersion, ExecutableChecksum(), lastCommitSHA, lastCommitTime, gitBranch,
runtime.Version(), licenseInfo)
}

// PrintVersion prints version and other helpful information if --version.
Expand All @@ -97,3 +102,24 @@ func PrintVersion() {
func Version() string {
return dgraphVersion
}

// ExecutableChecksum returns a byte slice containing the SHA256 checksum of the executable.
// It returns a nil slice if there's an error trying to calculate the checksum.
func ExecutableChecksum() []byte {
execPath, err := os.Executable()
if err != nil {
return nil
}
execFile, err := os.Open(execPath)
if err != nil {
return nil
}
defer execFile.Close()

h := sha256.New()
if _, err := io.Copy(h, execFile); err != nil {
return nil
}

return h.Sum(nil)
}