From 4af1c7f1b2588452004c306de59290f4b001ebd2 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Tue, 12 Nov 2013 13:11:02 -0800 Subject: [PATCH] builder/vmware: Double check that OutputDirectory does not already exist The initial check in Builder.Prepare does not use the OutputDir interface. stepPrepareOutputDir also checks if OutputDir exists, error out there unless using -force so we get the same behavior when RemoteType is esx5. --- builder/vmware/step_prepare_output_dir.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/builder/vmware/step_prepare_output_dir.go b/builder/vmware/step_prepare_output_dir.go index ae5a3ba80..bd5ae45b8 100644 --- a/builder/vmware/step_prepare_output_dir.go +++ b/builder/vmware/step_prepare_output_dir.go @@ -1,6 +1,7 @@ package vmware import ( + "fmt" "github.com/mitchellh/multistep" "github.com/mitchellh/packer/packer" "log" @@ -24,9 +25,14 @@ func (s *stepPrepareOutputDir) Run(state multistep.StateBag) multistep.StepActio return multistep.ActionHalt } - if exists && config.PackerForce { - ui.Say("Deleting previous output directory...") - dir.RemoveAll() + if exists { + if config.PackerForce { + ui.Say("Deleting previous output directory...") + dir.RemoveAll() + } else { + state.Put("error", fmt.Errorf("Output directory '%s' already exists.", config.OutputDir)) + return multistep.ActionHalt + } } if err := dir.MkdirAll(); err != nil {