Skip to content

Commit

Permalink
Use syscall.Exec() on unix (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamlamar authored May 15, 2018
1 parent 8f0b02f commit 078a8e4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
12 changes: 0 additions & 12 deletions rungo.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,12 @@ import (
"io"
"net/http"
"os"
"os/exec"
"path/filepath"

log "github.com/Sirupsen/logrus"
"github.com/pkg/errors"
)

func runGo(binary, baseDir string, args []string) error {
goBinary := filepath.Join(baseDir, "go", "bin", binary)
cmd := exec.Command(goBinary, args...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

log.Debugf("Executing %q with arguments %v", goBinary, args)
return cmd.Run()
}

// Get the requested version, either from env variable or go-version file
func findVersion() string {
envVersion := findEnvVersion()
Expand Down
10 changes: 10 additions & 0 deletions rungo_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,21 @@ import (
"io"
"os"
"path/filepath"
"syscall"

log "github.com/Sirupsen/logrus"
"github.com/pkg/errors"
)

func runGo(binary, baseDir string, args []string) error {
goBinary := filepath.Join(baseDir, "go", "bin", binary)
binaryWithArgs := append([]string{goBinary}, args...)

log.Debugf("Executing %q with arguments %v", goBinary, args)
// generally won't return
return syscall.Exec(goBinary, binaryWithArgs, os.Environ())
}

func extractFile(golangArchive, baseDir string) error {
log.Debugf("Extracting %q", golangArchive)
err := os.MkdirAll(baseDir, os.ModeDir|0755)
Expand Down
12 changes: 12 additions & 0 deletions rungo_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@ import (
"archive/zip"
"io"
"os"
"os/exec"
"path/filepath"

log "github.com/Sirupsen/logrus"
"github.com/pkg/errors"
)

func runGo(binary, baseDir string, args []string) error {
goBinary := filepath.Join(baseDir, "go", "bin", binary)
cmd := exec.Command(goBinary, args...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

log.Debugf("Executing %q with arguments %v", goBinary, args)
return cmd.Run()
}

func extractFile(golangArchive, baseDir string) error {
log.Debugf("Extracting %q", golangArchive)
err := os.MkdirAll(baseDir, os.ModeDir|0755)
Expand Down

0 comments on commit 078a8e4

Please sign in to comment.