2013-06-11 18:45:52 -04:00
|
|
|
package virtualbox
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/mitchellh/multistep"
|
2013-06-27 22:23:40 -04:00
|
|
|
"github.com/mitchellh/packer/packer"
|
2013-06-11 18:45:52 -04:00
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
type stepPrepareOutputDir struct{}
|
|
|
|
|
|
|
|
func (stepPrepareOutputDir) Run(state map[string]interface{}) multistep.StepAction {
|
|
|
|
config := state["config"].(*config)
|
|
|
|
|
|
|
|
if err := os.MkdirAll(config.OutputDir, 0755); err != nil {
|
2013-06-20 00:07:53 -04:00
|
|
|
state["error"] = err
|
2013-06-11 18:45:52 -04:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2013-06-27 22:23:40 -04:00
|
|
|
func (stepPrepareOutputDir) Cleanup(state map[string]interface{}) {
|
|
|
|
_, cancelled := state[multistep.StateCancelled]
|
|
|
|
_, halted := state[multistep.StateHalted]
|
|
|
|
|
|
|
|
if cancelled || halted {
|
|
|
|
config := state["config"].(*config)
|
|
|
|
ui := state["ui"].(packer.Ui)
|
|
|
|
|
|
|
|
ui.Say("Deleting output directory...")
|
|
|
|
os.RemoveAll(config.OutputDir)
|
|
|
|
}
|
|
|
|
}
|