github.com/kikitux/packer@v0.10.1-0.20160322154024-6237df566f9f/builder/parallels/common/output_config.go (about) 1 package common 2 3 import ( 4 "fmt" 5 "os" 6 "path" 7 8 "github.com/mitchellh/packer/common" 9 "github.com/mitchellh/packer/template/interpolate" 10 ) 11 12 type OutputConfig struct { 13 OutputDir string `mapstructure:"output_directory"` 14 } 15 16 func (c *OutputConfig) Prepare(ctx *interpolate.Context, pc *common.PackerConfig) []error { 17 if c.OutputDir == "" { 18 c.OutputDir = fmt.Sprintf("output-%s", pc.PackerBuildName) 19 } 20 21 var errs []error 22 23 if path.IsAbs(c.OutputDir) { 24 c.OutputDir = path.Clean(c.OutputDir) 25 } else { 26 wd, err := os.Getwd() 27 if err != nil { 28 errs = append(errs, err) 29 } 30 c.OutputDir = path.Clean(path.Join(wd, c.OutputDir)) 31 } 32 33 if !pc.PackerForce { 34 if _, err := os.Stat(c.OutputDir); err == nil { 35 errs = append(errs, fmt.Errorf( 36 "Output directory '%s' already exists. It must not exist.", c.OutputDir)) 37 } 38 } 39 40 return errs 41 }