don't re-use a TempDir path

Rather than creating and immediately removing a temp directory to get a
random path name, fetch files into a subdirectory.
This commit is contained in:
James Bardin 2018-03-28 11:33:42 -04:00
parent 28c46d1a90
commit 15dc75720e
1 changed files with 3 additions and 5 deletions

View File

@ -3,6 +3,7 @@ package module
import ( import (
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath"
"github.com/hashicorp/go-getter" "github.com/hashicorp/go-getter"
) )
@ -37,13 +38,10 @@ func GetCopy(dst, src string) error {
if err != nil { if err != nil {
return err return err
} }
// FIXME: This isn't completely safe. Creating and removing our temp path
// exposes where to race to inject files.
if err := os.RemoveAll(tmpDir); err != nil {
return err
}
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
tmpDir = filepath.Join(tmpDir, "module")
// Get to that temporary dir // Get to that temporary dir
if err := getter.Get(tmpDir, src); err != nil { if err := getter.Get(tmpDir, src); err != nil {
return err return err