2013-12-25 18:01:57 -05:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2015-05-27 17:16:28 -04:00
|
|
|
|
|
|
|
"github.com/mitchellh/packer/common"
|
|
|
|
"github.com/mitchellh/packer/template/interpolate"
|
2013-12-25 18:01:57 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type OutputConfig struct {
|
|
|
|
OutputDir string `mapstructure:"output_directory"`
|
|
|
|
}
|
|
|
|
|
2015-05-27 17:16:28 -04:00
|
|
|
func (c *OutputConfig) Prepare(ctx *interpolate.Context, pc *common.PackerConfig) []error {
|
2013-12-25 18:01:57 -05:00
|
|
|
if c.OutputDir == "" {
|
|
|
|
c.OutputDir = fmt.Sprintf("output-%s", pc.PackerBuildName)
|
|
|
|
}
|
|
|
|
|
2015-05-27 17:16:28 -04:00
|
|
|
var errs []error
|
2013-12-25 18:01:57 -05:00
|
|
|
if !pc.PackerForce {
|
|
|
|
if _, err := os.Stat(c.OutputDir); err == nil {
|
|
|
|
errs = append(errs, fmt.Errorf(
|
|
|
|
"Output directory '%s' already exists. It must not exist.", c.OutputDir))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return errs
|
|
|
|
}
|