builder/virtualbox,vmware: retry removing output dir if fails

This commit is contained in:
Mitchell Hashimoto 2013-07-31 15:16:39 -07:00
parent 8ac03e4898
commit 558027465a
3 changed files with 25 additions and 2 deletions

View File

@ -17,6 +17,8 @@ BUG FIXES:
* builder/virtualbox,vmware: relative paths work properly as URL * builder/virtualbox,vmware: relative paths work properly as URL
configurations. [GH-215] configurations. [GH-215]
* builder/virtualbox,vmware: fix race condition in deleting the output
directory on Windows by retrying.
## 0.2.1 (July 26, 2013) ## 0.2.1 (July 26, 2013)

View File

@ -3,7 +3,9 @@ package virtualbox
import ( import (
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"log"
"os" "os"
"time"
) )
type stepPrepareOutputDir struct{} type stepPrepareOutputDir struct{}
@ -34,6 +36,14 @@ func (stepPrepareOutputDir) Cleanup(state map[string]interface{}) {
ui := state["ui"].(packer.Ui) ui := state["ui"].(packer.Ui)
ui.Say("Deleting output directory...") 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)
}
} }
} }

View File

@ -3,7 +3,9 @@ package vmware
import ( import (
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"log"
"os" "os"
"time"
) )
type stepPrepareOutputDir struct{} type stepPrepareOutputDir struct{}
@ -34,6 +36,15 @@ func (stepPrepareOutputDir) Cleanup(state map[string]interface{}) {
ui := state["ui"].(packer.Ui) ui := state["ui"].(packer.Ui)
ui.Say("Deleting output directory...") 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)
}
} }
} }