From 6c4af2d75fbdd4e35baade7677f6a5bda057d615 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 24 Dec 2013 23:16:13 -0700 Subject: [PATCH] builder/vmware/iso: convert stepShutdown to use OutputDir for cleanup --- builder/vmware/iso/step_shutdown.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/builder/vmware/iso/step_shutdown.go b/builder/vmware/iso/step_shutdown.go index fea2f129a..14810113c 100644 --- a/builder/vmware/iso/step_shutdown.go +++ b/builder/vmware/iso/step_shutdown.go @@ -8,7 +8,7 @@ import ( vmwcommon "github.com/mitchellh/packer/builder/vmware/common" "github.com/mitchellh/packer/packer" "log" - "path/filepath" + "regexp" "runtime" "strings" "time" @@ -31,6 +31,7 @@ type stepShutdown struct{} func (s *stepShutdown) Run(state multistep.StateBag) multistep.StepAction { comm := state.Get("communicator").(packer.Communicator) config := state.Get("config").(*config) + dir := state.Get("dir").(vmwcommon.OutputDir) driver := state.Get("driver").(vmwcommon.Driver) ui := state.Get("ui").(packer.Ui) vmxPath := state.Get("vmx_path").(string) @@ -95,12 +96,19 @@ func (s *stepShutdown) Run(state multistep.StateBag) multistep.StepAction { } ui.Message("Waiting for VMware to clean up after itself...") - lockPattern := filepath.Join(config.OutputDir, "*.lck") + lockRegex := regexp.MustCompile(`(?i)\.lck$`) timer := time.After(15 * time.Second) LockWaitLoop: for { - locks, err := filepath.Glob(lockPattern) + files, err := dir.ListFiles() if err == nil { + var locks []string + for _, file := range files { + if lockRegex.MatchString(file) { + locks = append(locks, file) + } + } + if len(locks) == 0 { log.Println("No more lock files found. VMware is clean.") break