Skip to content

Commit

Permalink
Refactor install dir func
Browse files Browse the repository at this point in the history
  • Loading branch information
paultyng committed Sep 3, 2020
1 parent feb3390 commit ef60ae2
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions tfinstall/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,26 @@ import (
"golang.org/x/crypto/openpgp"
)

func ensureInstallDir(installDir string) (string, error) {
if installDir == "" {
return ioutil.TempDir("", "tfexec")
}

if _, err := os.Stat(installDir); err != nil {
return "", fmt.Errorf("could not access directory %s for installing Terraform: %w", installDir, err)
}

return installDir, nil
}

func downloadWithVerification(ctx context.Context, tfVersion string, installDir string) (string, error) {
osName := runtime.GOOS
archName := runtime.GOARCH

// setup: ensure we have a place to put our downloaded terraform binary
var tfDir string
var err error
if installDir == "" {
tfDir, err = ioutil.TempDir("", "tfexec")
if err != nil {
return "", fmt.Errorf("failed to create temp dir: %s", err)
}
} else {
if _, err := os.Stat(installDir); err != nil {
return "", fmt.Errorf("could not access directory %s for installing Terraform: %s", installDir, err)
}
tfDir = installDir
tfDir, err := ensureInstallDir(installDir)
if err != nil {
return "", err
}

httpGetter := &getter.HttpGetter{
Expand Down

0 comments on commit ef60ae2

Please sign in to comment.