|
|
|
|
@ -17,16 +17,30 @@ import (
|
|
|
|
|
type StepOutputDir struct {
|
|
|
|
|
Force bool
|
|
|
|
|
Path string
|
|
|
|
|
|
|
|
|
|
cleanup bool
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *StepOutputDir) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
|
|
|
|
|
|
if _, err := os.Stat(s.Path); err == nil && s.Force {
|
|
|
|
|
if _, err := os.Stat(s.Path); err == nil {
|
|
|
|
|
if !s.Force {
|
|
|
|
|
err := fmt.Errorf(
|
|
|
|
|
"Output directory exists: %s\n\n"+
|
|
|
|
|
"Use the force flag to delete it prior to building.",
|
|
|
|
|
s.Path)
|
|
|
|
|
state.Put("error", err)
|
|
|
|
|
return multistep.ActionHalt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ui.Say("Deleting previous output directory...")
|
|
|
|
|
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)
|
|
|
|
|
@ -47,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)
|
|
|
|
|
|
|
|
|
|
|