github.com/HashDataInc/packer@v1.3.2/packer/config_file.go (about)

     1  package packer
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  )
     7  
     8  // ConfigFile returns the default path to the configuration file. On
     9  // Unix-like systems this is the ".packerconfig" file in the home directory.
    10  // On Windows, this is the "packer.config" file in the application data
    11  // directory.
    12  func ConfigFile() (string, error) {
    13  	return configFile()
    14  }
    15  
    16  // ConfigDir returns the configuration directory for Packer.
    17  func ConfigDir() (string, error) {
    18  	return configDir()
    19  }
    20  
    21  // ConfigTmpDir returns the configuration tmp directory for Packer
    22  func ConfigTmpDir() (string, error) {
    23  	if tmpdir := os.Getenv("PACKER_TMP_DIR"); tmpdir != "" {
    24  		return filepath.Abs(tmpdir)
    25  	}
    26  	configdir, err := configDir()
    27  	if err != nil {
    28  		return "", err
    29  	}
    30  	td := filepath.Join(configdir, "tmp")
    31  	_, err = os.Stat(td)
    32  	if os.IsNotExist(err) {
    33  		if err = os.MkdirAll(td, 0755); err != nil {
    34  			return "", err
    35  		}
    36  	} else if err != nil {
    37  		return "", err
    38  	}
    39  	return td, nil
    40  }