From 9a318ceddc6a486568ef5b5cd355db83cb8674c0 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 27 Jun 2013 22:23:40 -0400 Subject: [PATCH] builder/virtualbox, vmware: delete output dir if cancelled --- builder/virtualbox/step_prepare_output_dir.go | 14 +++++++++++++- builder/vmware/step_prepare_output_dir.go | 14 +++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/builder/virtualbox/step_prepare_output_dir.go b/builder/virtualbox/step_prepare_output_dir.go index 14e0fc7ff..48e1eabc7 100644 --- a/builder/virtualbox/step_prepare_output_dir.go +++ b/builder/virtualbox/step_prepare_output_dir.go @@ -2,6 +2,7 @@ package virtualbox import ( "github.com/mitchellh/multistep" + "github.com/mitchellh/packer/packer" "os" ) @@ -18,4 +19,15 @@ func (stepPrepareOutputDir) Run(state map[string]interface{}) multistep.StepActi return multistep.ActionContinue } -func (stepPrepareOutputDir) Cleanup(map[string]interface{}) {} +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) + } +} diff --git a/builder/vmware/step_prepare_output_dir.go b/builder/vmware/step_prepare_output_dir.go index 976f36b00..fd194c91c 100644 --- a/builder/vmware/step_prepare_output_dir.go +++ b/builder/vmware/step_prepare_output_dir.go @@ -2,6 +2,7 @@ package vmware import ( "github.com/mitchellh/multistep" + "github.com/mitchellh/packer/packer" "os" ) @@ -18,4 +19,15 @@ func (stepPrepareOutputDir) Run(state map[string]interface{}) multistep.StepActi return multistep.ActionContinue } -func (stepPrepareOutputDir) Cleanup(map[string]interface{}) {} +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) + } +}