Skip to content

Commit

Permalink
win: use os.TempDir (#51)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
fenollp authored Jan 29, 2018
1 parent fdeb5c4 commit 08a945d
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 15 deletions.
10 changes: 10 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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))

Expand Down
8 changes: 5 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ func init() {
nextURL = apiRoot + "/next"

loadSchemas()

makePwdID()
}

func main() {
Expand All @@ -72,7 +70,7 @@ Options:
Try:
export FUZZYMONKEY_API_KEY=42
` + binName + ` --update -v
` + binName + ` --update
` + binName + ` fuzz`

parser := &docopt.Parser{
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion misc/latest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
28 changes: 21 additions & 7 deletions pwd_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"hash/fnv"
"log"
"os"
"path"
"path/filepath"
"sort"
"strconv"
Expand All @@ -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) {
Expand Down

0 comments on commit 08a945d

Please sign in to comment.