Merge pull request #179 from jasonberanek/force-build
builder/virtualbox, vmware: Remove output directory in a step when "-force" flag step [GH-178]
This commit is contained in:
commit
276428a330
|
@ -220,10 +220,7 @@ func (b *Builder) Prepare(raws ...interface{}) error {
|
|||
}
|
||||
|
||||
if _, err := os.Stat(b.config.OutputDir); err == nil {
|
||||
if b.config.PackerForce {
|
||||
log.Printf("Build forced, removing existing output directory: %s", string(b.config.OutputDir))
|
||||
os.RemoveAll(b.config.OutputDir)
|
||||
} else {
|
||||
if !b.config.PackerForce {
|
||||
errs = append(errs, errors.New("Output directory already exists. It must not exist."))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,12 @@ type stepPrepareOutputDir struct{}
|
|||
|
||||
func (stepPrepareOutputDir) Run(state map[string]interface{}) multistep.StepAction {
|
||||
config := state["config"].(*config)
|
||||
ui := state["ui"].(packer.Ui)
|
||||
|
||||
if _, err := os.Stat(config.OutputDir); err == nil && config.PackerForce {
|
||||
ui.Say("Deleting previous output directory...")
|
||||
os.RemoveAll(config.OutputDir)
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(config.OutputDir, 0755); err != nil {
|
||||
state["error"] = err
|
||||
|
|
|
@ -176,10 +176,7 @@ func (b *Builder) Prepare(raws ...interface{}) error {
|
|||
}
|
||||
|
||||
if _, err := os.Stat(b.config.OutputDir); err == nil {
|
||||
if b.config.PackerForce {
|
||||
log.Printf("Build forced, removing existing output directory: %s", string(b.config.OutputDir))
|
||||
os.RemoveAll(b.config.OutputDir)
|
||||
} else {
|
||||
if !b.config.PackerForce {
|
||||
errs = append(errs, errors.New("Output directory already exists. It must not exist."))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,12 @@ type stepPrepareOutputDir struct{}
|
|||
|
||||
func (stepPrepareOutputDir) Run(state map[string]interface{}) multistep.StepAction {
|
||||
config := state["config"].(*config)
|
||||
ui := state["ui"].(packer.Ui)
|
||||
|
||||
if _, err := os.Stat(config.OutputDir); err == nil && config.PackerForce {
|
||||
ui.Say("Deleting previous output directory...")
|
||||
os.RemoveAll(config.OutputDir)
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(config.OutputDir, 0755); err != nil {
|
||||
state["error"] = err
|
||||
|
|
Loading…
Reference in New Issue