From 0d97a985945f7ddff8ad16731ec695a6bcba57c7 Mon Sep 17 00:00:00 2001 From: "Anand Babu (AB) Periasamy" Date: Sun, 26 Apr 2015 02:58:10 -0700 Subject: [PATCH] Version is now based on MD5SUM of its binary --- hash-binary.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/hash-binary.go b/hash-binary.go index aaf3a24e1..2344a4c4e 100644 --- a/hash-binary.go +++ b/hash-binary.go @@ -4,24 +4,30 @@ import ( "fmt" "io" "os" + "os/exec" "crypto/md5" ) -// mustHashBinarySelf computes MD5SUM of a binary file on disk +// hashBinary computes MD5SUM of a binary file on disk func hashBinary(progName string) (string, error) { - h := md5.New() - - file, err := os.Open(progName) // For read access. + path, err := exec.LookPath(progName) if err != nil { return "", err } - io.Copy(h, file) - return fmt.Sprintf("%x", h.Sum(nil)), nil + m := md5.New() + + file, err := os.Open(path) // For read access. + if err != nil { + return "", err + } + + io.Copy(m, file) + return fmt.Sprintf("%x", m.Sum(nil)), nil } -// mustHashBinarySelf computes MD5SUM of its binary file on disk +// mustHashBinarySelf masks any error returned by hashBinary func mustHashBinarySelf() string { hash, _ := hashBinary(os.Args[0]) return hash