diff --git a/packer/config_file.go b/packer/config_file.go index edd10edee..3bd9cfe8d 100644 --- a/packer/config_file.go +++ b/packer/config_file.go @@ -20,17 +20,24 @@ func ConfigDir() (string, error) { // ConfigTmpDir returns the configuration tmp directory for Packer func ConfigTmpDir() (string, error) { - if tmpdir := os.Getenv("PACKER_TMP_DIR"); tmpdir != "" { - return filepath.Abs(tmpdir) + var tmpdir, td string + var found bool + + if tmpdir = os.Getenv("PACKER_TMP_DIR"); tmpdir == "" { + for e := range []string{"TEMP", "TMP", "LOCALAPPDATA"} { + if tmpdir, found := os.LookupEnv(e); found { + td = filepath.Join(tmpdir, "packer") + break + } + } } - configdir, err := configDir() - if err != nil { - return "", err + if tmpdir == "" { + td = filepath.Join(configDir(), "tmp") } - td := filepath.Join(configdir, "tmp") + _, err = os.Stat(td) if os.IsNotExist(err) { - if err = os.MkdirAll(td, 0755); err != nil { + if err = os.MkdirAll(td, 0700); err != nil { return "", err } } else if err != nil { diff --git a/packer/config_file_unix.go b/packer/config_file_unix.go index 512ac42ed..9b55cd9b6 100644 --- a/packer/config_file_unix.go +++ b/packer/config_file_unix.go @@ -18,7 +18,7 @@ func configFile() (string, error) { return "", err } - return filepath.Join(dir, ".packerconfig"), nil + return filepath.Join(dir, "packer.config"), nil } func configDir() (string, error) { diff --git a/website/source/docs/other/debugging.html.md b/website/source/docs/other/debugging.html.md index 367e81061..8f45df932 100644 --- a/website/source/docs/other/debugging.html.md +++ b/website/source/docs/other/debugging.html.md @@ -139,4 +139,4 @@ Failed to initialize build 'docker': error initializing builder 'docker': plugin ``` you should try setting your temp directory to something shorter. This can be -done through the `TMPDIR` environment variable. +done through the `PACKER_TMP_DIR` environment variable. diff --git a/website/source/docs/other/environment-variables.html.md b/website/source/docs/other/environment-variables.html.md index cd36ef1ad..a5e86dec6 100644 --- a/website/source/docs/other/environment-variables.html.md +++ b/website/source/docs/other/environment-variables.html.md @@ -42,9 +42,10 @@ each can be found below: new versions of Packer. If you want to disable this for security or privacy reasons, you can set this environment variable to `1`. -- `TMPDIR` (Unix) / `TMP` (Windows) - The location of the directory used for - temporary files (defaults to `/tmp` on Linux/Unix and - `%USERPROFILE%\AppData\Local\Temp` on Windows Vista and above). It might be - necessary to customize it when working with large files since `/tmp` is a - memory-backed filesystem in some Linux distributions in which case - `/var/tmp` might be preferred. +- `PACKER_TMP_DIR` - The directory used for temporary files during marshalling. + If unset, appends 'packer' to environment variables TEMP, TMP, or LOCALAPPDATA + (Windows) before falling back to the value of `configDir()/tmp` which resolves + to `$HOME/.packer.d/` (Unix) or `%APPDAT%\packer.d` (Windows). + This is not to be confused with the provisionee's temporary directory which + is often defined (hard-coded) as '/tmp' or '%SYSTEMROOT%\Temp' per each + provisioner module.