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 {
Force bool
Path string
cleanup bool
}
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)
}
// Enable cleanup
s.cleanup = true
// Create the directory
if err := os.MkdirAll(s.Path, 0755); err != nil {
state.Put("error", err)
@ -56,6 +61,10 @@ func (s *StepOutputDir) Run(state multistep.StateBag) multistep.StepAction {
}
func (s *StepOutputDir) Cleanup(state multistep.StateBag) {
if !s.cleanup {
return
}
_, cancelled := state.GetOk(multistep.StateCancelled)
_, halted := state.GetOk(multistep.StateHalted)