builder/virtualbox: only remove output dir after check

This commit is contained in:
Mitchell Hashimoto 2015-06-22 09:09:12 -07:00
parent 897888fde3
commit 54e081d5af
1 changed files with 9 additions and 0 deletions

View File

@ -17,6 +17,8 @@ import (
type StepOutputDir struct { type StepOutputDir struct {
Force bool Force bool
Path string Path string
cleanup bool
} }
func (s *StepOutputDir) Run(state multistep.StateBag) multistep.StepAction { func (s *StepOutputDir) Run(state multistep.StateBag) multistep.StepAction {
@ -36,6 +38,9 @@ func (s *StepOutputDir) Run(state multistep.StateBag) multistep.StepAction {
os.RemoveAll(s.Path) os.RemoveAll(s.Path)
} }
// Enable cleanup
s.cleanup = true
// Create the directory // Create the directory
if err := os.MkdirAll(s.Path, 0755); err != nil { if err := os.MkdirAll(s.Path, 0755); err != nil {
state.Put("error", err) state.Put("error", err)
@ -56,6 +61,10 @@ func (s *StepOutputDir) Run(state multistep.StateBag) multistep.StepAction {
} }
func (s *StepOutputDir) Cleanup(state multistep.StateBag) { func (s *StepOutputDir) Cleanup(state multistep.StateBag) {
if !s.cleanup {
return
}
_, cancelled := state.GetOk(multistep.StateCancelled) _, cancelled := state.GetOk(multistep.StateCancelled)
_, halted := state.GetOk(multistep.StateHalted) _, halted := state.GetOk(multistep.StateHalted)