mirror of https://github.com/hashicorp/packer
Merge pull request #2846 from markpeek/packer-tmp
Create docker temp files under packer.d when TMPDIR is not setpull/2876/head
commit
ba7814b0ed
@ -0,0 +1,40 @@
|
|||||||
|
package packer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ConfigFile returns the default path to the configuration file. On
|
||||||
|
// Unix-like systems this is the ".packerconfig" file in the home directory.
|
||||||
|
// On Windows, this is the "packer.config" file in the application data
|
||||||
|
// directory.
|
||||||
|
func ConfigFile() (string, error) {
|
||||||
|
return configFile()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ConfigDir returns the configuration directory for Packer.
|
||||||
|
func ConfigDir() (string, error) {
|
||||||
|
return configDir()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ConfigTmpDir returns the configuration tmp directory for Packer
|
||||||
|
func ConfigTmpDir() (string, error) {
|
||||||
|
if tmpdir := os.Getenv("PACKER_TMP_DIR"); tmpdir != "" {
|
||||||
|
return filepath.Abs(tmpdir)
|
||||||
|
}
|
||||||
|
configdir, err := configDir()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
td := filepath.Join(configdir, "tmp")
|
||||||
|
_, err = os.Stat(td)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
if err = os.MkdirAll(td, 0755); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
} else if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return td, nil
|
||||||
|
}
|
||||||
@ -1,6 +1,6 @@
|
|||||||
// +build darwin freebsd linux netbsd openbsd
|
// +build darwin freebsd linux netbsd openbsd
|
||||||
|
|
||||||
package main
|
package packer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@ -1,6 +1,6 @@
|
|||||||
// +build windows
|
// +build windows
|
||||||
|
|
||||||
package main
|
package packer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
Loading…
Reference in new issue