start handling stupid Windows

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-06-13 19:31:37 -07:00
parent b375aa752a
commit 49d36e287d
3 changed files with 50 additions and 3 deletions

35
md5sum.go Normal file
View File

@ -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 ""
}

View File

@ -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

10
windowsWrapper.go Normal file
View File

@ -0,0 +1,10 @@
package shell
import "runtime"
func Execname(filename string) string {
if runtime.GOOS == "windows" {
return filename + ".exe"
}
return filename
}