Merge pull request #494 from abperiasamy/md5sum-path-bug
Version is now based on MD5SUM of its binary
This commit is contained in:
commit
f7d2711d60
1 changed files with 13 additions and 7 deletions
|
@ -4,24 +4,30 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
|
||||||
"crypto/md5"
|
"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) {
|
func hashBinary(progName string) (string, error) {
|
||||||
h := md5.New()
|
path, err := exec.LookPath(progName)
|
||||||
|
|
||||||
file, err := os.Open(progName) // For read access.
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
io.Copy(h, file)
|
m := md5.New()
|
||||||
return fmt.Sprintf("%x", h.Sum(nil)), nil
|
|
||||||
|
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 {
|
func mustHashBinarySelf() string {
|
||||||
hash, _ := hashBinary(os.Args[0])
|
hash, _ := hashBinary(os.Args[0])
|
||||||
return hash
|
return hash
|
||||||
|
|
Loading…
Reference in a new issue