From 08a945d8aa4503651602f544c01303a0de5e2027 Mon Sep 17 00:00:00 2001 From: Pierre Fenoll Date: Mon, 29 Jan 2018 14:09:40 +0100 Subject: [PATCH] win: use os.TempDir (#51) * resolve symlinks for pwdID * win: less Panics more Printlns * win: use os.TempDir * win: .appveyor.yml * win: fix around uname-s for Windows * win: add 32b to .appveyor.yml * win: fix #13 --- .appveyor.yml | 10 ++++++++++ .travis.yml | 4 +++- Makefile | 13 ++++++++++--- main.go | 8 +++++--- misc/latest.sh | 2 +- pwd_id.go | 28 +++++++++++++++++++++------- 6 files changed, 50 insertions(+), 15 deletions(-) create mode 100644 .appveyor.yml diff --git a/.appveyor.yml b/.appveyor.yml new file mode 100644 index 00000000..4c7ccad3 --- /dev/null +++ b/.appveyor.yml @@ -0,0 +1,10 @@ +version: '{build}' +platform: + - x64 + - x86 +clone_folder: c:\gopath\src\github.com\FuzzyMonkeyCo\monkey + +build_script: + - curl -#fSLo latest.sh http://goo.gl/3d7tPe -A "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0" -e https://ci.appveyor.com/project/fenollp/monkey + - bash latest.sh + - monkey -vvv --update diff --git a/.travis.yml b/.travis.yml index 787a6aee..d6a49782 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,12 +44,14 @@ script: - go vet $(go list ./... | grep -v /vendor/) - megacheck -show-ignored -unused.exported #- go test -v -race . - - make x + - OSARCH=linux/amd64 make x - '[[ 0 -eq $(git --no-pager diff --name-only | wc -l) ]]' - ./monkey-Linux-x86_64 -h | grep monkey - ./monkey-Linux-x86_64 --help | grep monkey - ./monkey-Linux-x86_64 -V | grep monkey/$CURRENT_TAG - ./monkey-Linux-x86_64 --version | grep monkey/$CURRENT_TAG + - make x + - '[[ 0 -eq $(git --no-pager diff --name-only | wc -l) ]]' - make image - docker tag monkey fuzzymonkey/monkey:$CURRENT_TAG - docker tag monkey fuzzymonkey/monkey:latest diff --git a/Makefile b/Makefile index ce12f2b6..6dba326c 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,15 @@ .PHONY: all update debug lint x test EXE = monkey -OS ?= linux darwin windows -ARCH ?= amd64 +OSARCH ?= \ + windows/386 windows/amd64 \ + darwin/386 darwin/amd64 \ + linux/386 linux/amd64 linux/arm linux/arm64 linux/mips linux/mipsle \ + freebsd/386 freebsd/amd64 freebsd/arm \ + netbsd/386 netbsd/amd64 netbsd/arm \ + openbsd/386 openbsd/amd64 \ + plan9/386 plan9/amd64 \ + solaris/amd64 SHA = sha256.txt FMT = $(EXE)-{{.OSUname}}-{{.ArchUname}} LNX = $(EXE)-Linux-x86_64 @@ -18,7 +25,7 @@ all: lint vendor x: vendor $(if $(wildcard $(EXE)-*-*.$(SHA)),rm $(EXE)-*-*.$(SHA)) go generate - CGO_ENABLED=0 gox -os '$(OS)' -arch '$(ARCH)' -output '$(DST)/$(FMT)' -ldflags '-s -w' -verbose . + CGO_ENABLED=0 gox -output '$(DST)/$(FMT)' -ldflags '-s -w' -verbose -osarch "$$(echo $(OSARCH))" . cd $(DST) && for bin in $(EXE)-*; do sha256sum $$bin | tee $$bin.$(SHA); done $(if $(filter-out .,$(DST)),,sha256sum --check --strict *$(SHA)) diff --git a/main.go b/main.go index 22448044..ea54bfb7 100644 --- a/main.go +++ b/main.go @@ -46,8 +46,6 @@ func init() { nextURL = apiRoot + "/next" loadSchemas() - - makePwdID() } func main() { @@ -72,7 +70,7 @@ Options: Try: export FUZZYMONKEY_API_KEY=42 - ` + binName + ` --update -v + ` + binName + ` --update ` + binName + ` fuzz` parser := &docopt.Parser{ @@ -93,6 +91,10 @@ func actualMain() int { return 0 } + if err := makePwdID(); err != nil { + return retryOrReport() + } + logCatchall, err := os.OpenFile(logID(), os.O_WRONLY|os.O_CREATE, 0640) if err != nil { log.Println(err) diff --git a/misc/latest.sh b/misc/latest.sh index dc5062b6..72441f4f 100755 --- a/misc/latest.sh +++ b/misc/latest.sh @@ -54,7 +54,7 @@ fi exe=monkey-"$(uname -s)-$(uname -m)" case "$exe" in - CYGWIN*|MINGW32*|MSYS*) exe=$exe.exe ;; + CYGWIN*|MINGW32*|MSYS*) exe=monkey-Windows-"$(uname -m)".exe ;; esac echo "Downloading v$latest_tag of $exe" diff --git a/pwd_id.go b/pwd_id.go index 28ef1a09..38489b29 100644 --- a/pwd_id.go +++ b/pwd_id.go @@ -5,6 +5,7 @@ import ( "hash/fnv" "log" "os" + "path" "path/filepath" "sort" "strconv" @@ -25,22 +26,35 @@ func updateID() string { return pwdID + "_update.bin" } -func makePwdID() { +func makePwdID() (err error) { cwd, err := os.Getwd() if err != nil { - log.Panic("[ERR] ", err) + log.Println("[ERR]", err) + return + } + realCwd, err := filepath.EvalSymlinks(cwd) + if err != nil { + log.Println("[ERR]", err) + return } + tmp := os.TempDir() + if err = os.MkdirAll(tmp, 0700); err != nil { + log.Println("[ERR]", err) + return + } h := fnv.New64a() - h.Write([]byte(cwd)) - id := "/tmp/." + binName + "_" + fmt.Sprintf("%d", h.Sum64()) + h.Write([]byte(realCwd)) + id := fmt.Sprintf("%d", h.Sum64()) + prefix := path.Join(tmp, "."+binName+"_"+id) - slot, err := findNewIDSlot(id) + slot, err := findNewIDSlot(prefix) if err != nil { - log.Panic("[ERR] ", err) + return } - pwdID = id + "_" + slot + pwdID = prefix + "_" + slot + return } func findNewIDSlot(prefix string) (slot string, err error) {