From 8f8ea60b4fd569f90d67a4655d4f2498323b703c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 24 Dec 2013 18:17:58 -0700 Subject: [PATCH] builder/vmware/common: StepCleanFiles --- builder/vmware/{iso => common}/step_clean_files.go | 12 +++++++----- builder/vmware/iso/builder.go | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) rename builder/vmware/{iso => common}/step_clean_files.go (79%) diff --git a/builder/vmware/iso/step_clean_files.go b/builder/vmware/common/step_clean_files.go similarity index 79% rename from builder/vmware/iso/step_clean_files.go rename to builder/vmware/common/step_clean_files.go index f6c3f0fa4..de3debccc 100644 --- a/builder/vmware/iso/step_clean_files.go +++ b/builder/vmware/common/step_clean_files.go @@ -1,4 +1,4 @@ -package iso +package common import ( "fmt" @@ -21,9 +21,9 @@ var KeepFileExtensions = []string{".nvram", ".vmdk", ".vmsd", ".vmx", ".vmxf"} // // Produces: // -type stepCleanFiles struct{} +type StepCleanFiles struct{} -func (stepCleanFiles) Run(state multistep.StateBag) multistep.StepAction { +func (StepCleanFiles) Run(state multistep.StateBag) multistep.StepAction { dir := state.Get("dir").(OutputDir) ui := state.Get("ui").(packer.Ui) @@ -49,7 +49,9 @@ func (stepCleanFiles) Run(state multistep.StateBag) multistep.StepAction { if !keep { ui.Message(fmt.Sprintf("Deleting: %s", path)) if err = dir.Remove(path); err != nil { - // Only report the error if the file still exists + // Only report the error if the file still exists. We do this + // because sometimes the files naturally get removed on their + // own as VMware does its own cleanup. if _, serr := os.Stat(path); serr == nil || !os.IsNotExist(serr) { state.Put("error", err) return multistep.ActionHalt @@ -61,4 +63,4 @@ func (stepCleanFiles) Run(state multistep.StateBag) multistep.StepAction { return multistep.ActionContinue } -func (stepCleanFiles) Cleanup(multistep.StateBag) {} +func (StepCleanFiles) Cleanup(multistep.StateBag) {} diff --git a/builder/vmware/iso/builder.go b/builder/vmware/iso/builder.go index da9d71dec..a829f1a93 100644 --- a/builder/vmware/iso/builder.go +++ b/builder/vmware/iso/builder.go @@ -411,7 +411,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe &stepUploadTools{}, &common.StepProvision{}, &stepShutdown{}, - &stepCleanFiles{}, + &vmwcommon.StepCleanFiles{}, &stepCleanVMX{}, &stepCompactDisk{}, }