Commit 276428a3 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

Merge pull request #179 from jasonberanek/force-build

builder/virtualbox, vmware: Remove output directory in a step when "-force" flag step [GH-178]
parents 1dad4749 9c31c69a
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment