Commit 9c31c69a authored by Jason A. Beranek's avatar Jason A. Beranek

Remove output directory in a step when "-force" flag step [GH-178]

parent 1dad4749
......@@ -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