From 49d36e287d983f72b2b2b5d903fb3bf55a44b440 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 13 Jun 2019 19:31:37 -0700 Subject: [PATCH] start handling stupid Windows Signed-off-by: Jeff Carr --- md5sum.go | 35 +++++++++++++++++++++++++++++++++++ shell.go | 8 +++++--- windowsWrapper.go | 10 ++++++++++ 3 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 md5sum.go create mode 100644 windowsWrapper.go diff --git a/md5sum.go b/md5sum.go new file mode 100644 index 0000000..74ec106 --- /dev/null +++ b/md5sum.go @@ -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 "" +} diff --git a/shell.go b/shell.go index 47ff9ed..ab8a695 100644 --- a/shell.go +++ b/shell.go @@ -13,7 +13,9 @@ import "io" import "github.com/davecgh/go-spew/spew" import "github.com/svent/go-nbreader" +// import "log" import log "github.com/sirupsen/logrus" +// TODO this journalhook to be cross platform // import "github.com/wercker/journalhook" // TODO: look at https://github.com/go-cmd/cmd/issues/20 @@ -24,9 +26,9 @@ var callback func(interface{}, int) var shellStdout *os.File var shellStderr *os.File -var spewOn bool = false -var quiet bool = false -var msecDelay int = 20 // number of milliseconds to delay between reads with no data +var spewOn bool = false +var quiet bool = false +var msecDelay int = 20 // number of milliseconds to delay between reads with no data var bytesBuffer bytes.Buffer var bytesSplice []byte diff --git a/windowsWrapper.go b/windowsWrapper.go new file mode 100644 index 0000000..a33bb8b --- /dev/null +++ b/windowsWrapper.go @@ -0,0 +1,10 @@ +package shell + +import "runtime" + +func Execname(filename string) string { + if runtime.GOOS == "windows" { + return filename + ".exe" + } + return filename +}