-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
output_config.go
43 lines (35 loc) · 993 Bytes
/
output_config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package common
import (
"fmt"
"os"
"path"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/template/interpolate"
)
// OutputConfig contains the configuration for builder's output.
type OutputConfig struct {
OutputDir string `mapstructure:"output_directory"`
}
// Prepare configures the output directory or returns an error if it already exists.
func (c *OutputConfig) Prepare(ctx *interpolate.Context, pc *common.PackerConfig) []error {
if c.OutputDir == "" {
c.OutputDir = fmt.Sprintf("output-%s", pc.PackerBuildName)
}
var errs []error
if path.IsAbs(c.OutputDir) {
c.OutputDir = path.Clean(c.OutputDir)
} else {
wd, err := os.Getwd()
if err != nil {
errs = append(errs, err)
}
c.OutputDir = path.Clean(path.Join(wd, c.OutputDir))
}
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
}