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
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 {

@ -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) {

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

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

Loading…
Cancel
Save