start handling stupid Windows
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
b375aa752a
commit
49d36e287d
|
@ -0,0 +1,35 @@
|
||||||
|
package shell
|
||||||
|
|
||||||
|
import "crypto/md5"
|
||||||
|
import "encoding/hex"
|
||||||
|
import "log"
|
||||||
|
import "io"
|
||||||
|
import "os"
|
||||||
|
|
||||||
|
func hash_file_md5(filePath string) (string, error) {
|
||||||
|
var returnMD5String string
|
||||||
|
file, err := os.Open(filePath)
|
||||||
|
if err != nil {
|
||||||
|
return returnMD5String, err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
hash := md5.New()
|
||||||
|
if _, err := io.Copy(hash, file); err != nil {
|
||||||
|
return returnMD5String, err
|
||||||
|
}
|
||||||
|
hashInBytes := hash.Sum(nil)[:16]
|
||||||
|
returnMD5String = hex.EncodeToString(hashInBytes)
|
||||||
|
return returnMD5String, nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// hash thyself: hash_file_md5(os.Args[0])
|
||||||
|
func Md5sum(filename string) string {
|
||||||
|
hash, err := hash_file_md5(filename)
|
||||||
|
if err == nil {
|
||||||
|
log.Println("shell.Md5sum() hash =", hash)
|
||||||
|
return hash
|
||||||
|
}
|
||||||
|
log.Println("shell.Md5sum() failed")
|
||||||
|
return ""
|
||||||
|
}
|
2
shell.go
2
shell.go
|
@ -13,7 +13,9 @@ import "io"
|
||||||
import "github.com/davecgh/go-spew/spew"
|
import "github.com/davecgh/go-spew/spew"
|
||||||
import "github.com/svent/go-nbreader"
|
import "github.com/svent/go-nbreader"
|
||||||
|
|
||||||
|
// import "log"
|
||||||
import log "github.com/sirupsen/logrus"
|
import log "github.com/sirupsen/logrus"
|
||||||
|
// TODO this journalhook to be cross platform
|
||||||
// import "github.com/wercker/journalhook"
|
// import "github.com/wercker/journalhook"
|
||||||
|
|
||||||
// TODO: look at https://github.com/go-cmd/cmd/issues/20
|
// TODO: look at https://github.com/go-cmd/cmd/issues/20
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
package shell
|
||||||
|
|
||||||
|
import "runtime"
|
||||||
|
|
||||||
|
func Execname(filename string) string {
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
return filename + ".exe"
|
||||||
|
}
|
||||||
|
return filename
|
||||||
|
}
|
Loading…
Reference in New Issue