replace invalid TMPDIR variable wth PACKER_TMP_DIR.

update ConfigTmpDir() to try common temporary paths first and
only write to configDir() as a last resort.
pull/6942/head
Matthew Patton 8 years ago committed by Matthew Patton
parent daf1f39930
commit 95159afbc0

@ -20,17 +20,24 @@ func ConfigDir() (string, error) {
// ConfigTmpDir returns the configuration tmp directory for Packer // ConfigTmpDir returns the configuration tmp directory for Packer
func ConfigTmpDir() (string, error) { func ConfigTmpDir() (string, error) {
if tmpdir := os.Getenv("PACKER_TMP_DIR"); tmpdir != "" { var tmpdir, td string
return filepath.Abs(tmpdir) 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 tmpdir == "" {
if err != nil { td = filepath.Join(configDir(), "tmp")
return "", err
} }
td := filepath.Join(configdir, "tmp")
_, err = os.Stat(td) _, err = os.Stat(td)
if os.IsNotExist(err) { if os.IsNotExist(err) {
if err = os.MkdirAll(td, 0755); err != nil { if err = os.MkdirAll(td, 0700); err != nil {
return "", err return "", err
} }
} else if err != nil { } else if err != nil {

@ -18,7 +18,7 @@ func configFile() (string, error) {
return "", err return "", err
} }
return filepath.Join(dir, ".packerconfig"), nil return filepath.Join(dir, "packer.config"), nil
} }
func configDir() (string, error) { func configDir() (string, error) {

@ -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 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.

@ -42,9 +42,10 @@ each can be found below:
new versions of Packer. If you want to disable this for security or privacy new versions of Packer. If you want to disable this for security or privacy
reasons, you can set this environment variable to `1`. reasons, you can set this environment variable to `1`.
- `TMPDIR` (Unix) / `TMP` (Windows) - The location of the directory used for - `PACKER_TMP_DIR` - The directory used for temporary files during marshalling.
temporary files (defaults to `/tmp` on Linux/Unix and If unset, appends 'packer' to environment variables TEMP, TMP, or LOCALAPPDATA
`%USERPROFILE%\AppData\Local\Temp` on Windows Vista and above). It might be (Windows) before falling back to the value of `configDir()/tmp` which resolves
necessary to customize it when working with large files since `/tmp` is a to `$HOME/.packer.d/` (Unix) or `%APPDAT%\packer.d` (Windows).
memory-backed filesystem in some Linux distributions in which case This is not to be confused with the provisionee's temporary directory which
`/var/tmp` might be preferred. is often defined (hard-coded) as '/tmp' or '%SYSTEMROOT%\Temp' per each
provisioner module.

Loading…
Cancel
Save