Merge pull request #7905 from hashicorp/set_config_dir

make sure we create the temp dir explicitly when we are setting up th…
This commit is contained in:
Megan Marsh 2019-07-25 11:35:50 -07:00 committed by GitHub
commit 175d0b817d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 3 deletions

View File

@ -3,6 +3,7 @@ package docker
import (
"context"
"fmt"
"log"
"os"
"path/filepath"
@ -18,22 +19,32 @@ type StepTempDir struct {
// ConfigTmpDir returns the configuration tmp directory for Docker
func ConfigTmpDir() (string, error) {
if tmpdir := os.Getenv("PACKER_TMP_DIR"); tmpdir != "" {
return filepath.Abs(tmpdir)
}
configdir, err := packer.ConfigDir()
if err != nil {
return "", err
}
if tmpdir := os.Getenv("PACKER_TMP_DIR"); tmpdir != "" {
// override the config dir with tmp dir. Still stat it and mkdirall if
// necessary.
fp, err := filepath.Abs(tmpdir)
log.Printf("found PACKER_TMP_DIR env variable; setting tmpdir to %s", fp)
if err != nil {
return "", err
}
configdir = fp
}
td := filepath.Join(configdir, "tmp")
_, err = os.Stat(td)
if os.IsNotExist(err) {
log.Printf("Creating tempdir in %s", td)
if err = os.MkdirAll(td, 0755); err != nil {
return "", err
}
} else if err != nil {
return "", err
}
log.Printf("Set Packer temp dir to %s", td)
return td, nil
}