Merge pull request #8192 from hashicorp/fix_7904

use a unique temp dir for each build to prevent concurrent builds fro…
This commit is contained in:
Megan Marsh 2019-10-04 09:39:03 -07:00 committed by GitHub
commit e3257ba088
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -3,6 +3,7 @@ package docker
import (
"context"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
@ -34,16 +35,21 @@ func ConfigTmpDir() (string, error) {
configdir = fp
}
td := filepath.Join(configdir, "tmp")
_, err = os.Stat(td)
_, err = os.Stat(configdir)
if os.IsNotExist(err) {
log.Printf("Creating tempdir in %s", td)
if err = os.MkdirAll(td, 0755); err != nil {
log.Printf("Config dir %s does not exist; creating...", configdir)
if err = os.MkdirAll(configdir, 0755); err != nil {
return "", err
}
} else if err != nil {
return "", err
}
td, err := ioutil.TempDir(configdir, "tmp")
if err != nil {
return "", fmt.Errorf("Error creating temp dir: %s", err)
}
log.Printf("Set Packer temp dir to %s", td)
return td, nil
}

View File

@ -35,7 +35,7 @@ func testStepTempDir_impl(t *testing.T) string {
dir := dirRaw.(string)
if _, err := os.Stat(dir); err != nil {
t.Fatalf("err: %s", err)
t.Fatalf("Stat for %s failed: err: %s", err, dir)
}
// Cleanup