From 558027465a1c39248228c999a4ae885e27699cda Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 31 Jul 2013 15:16:39 -0700 Subject: [PATCH] builder/virtualbox,vmware: retry removing output dir if fails --- CHANGELOG.md | 2 ++ builder/virtualbox/step_prepare_output_dir.go | 12 +++++++++++- builder/vmware/step_prepare_output_dir.go | 13 ++++++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8f250c09..406fed67a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ BUG FIXES: * builder/virtualbox,vmware: relative paths work properly as URL configurations. [GH-215] +* builder/virtualbox,vmware: fix race condition in deleting the output + directory on Windows by retrying. ## 0.2.1 (July 26, 2013) diff --git a/builder/virtualbox/step_prepare_output_dir.go b/builder/virtualbox/step_prepare_output_dir.go index 102f71035..12f5a2e86 100644 --- a/builder/virtualbox/step_prepare_output_dir.go +++ b/builder/virtualbox/step_prepare_output_dir.go @@ -3,7 +3,9 @@ package virtualbox import ( "github.com/mitchellh/multistep" "github.com/mitchellh/packer/packer" + "log" "os" + "time" ) type stepPrepareOutputDir struct{} @@ -34,6 +36,14 @@ func (stepPrepareOutputDir) Cleanup(state map[string]interface{}) { ui := state["ui"].(packer.Ui) ui.Say("Deleting output directory...") - os.RemoveAll(config.OutputDir) + for i := 0; i < 5; i++ { + err := os.RemoveAll(config.OutputDir) + if err == nil { + break + } + + log.Printf("Error removing output dir: %s", err) + time.Sleep(2 * time.Second) + } } } diff --git a/builder/vmware/step_prepare_output_dir.go b/builder/vmware/step_prepare_output_dir.go index f773ecf58..6919f676c 100644 --- a/builder/vmware/step_prepare_output_dir.go +++ b/builder/vmware/step_prepare_output_dir.go @@ -3,7 +3,9 @@ package vmware import ( "github.com/mitchellh/multistep" "github.com/mitchellh/packer/packer" + "log" "os" + "time" ) type stepPrepareOutputDir struct{} @@ -34,6 +36,15 @@ func (stepPrepareOutputDir) Cleanup(state map[string]interface{}) { ui := state["ui"].(packer.Ui) ui.Say("Deleting output directory...") - os.RemoveAll(config.OutputDir) + + for i := 0; i < 5; i++ { + err := os.RemoveAll(config.OutputDir) + if err == nil { + break + } + + log.Printf("Error removing output dir: %s", err) + time.Sleep(2 * time.Second) + } } }