builder/vmware/common: StepCleanFiles

This commit is contained in:
Mitchell Hashimoto 2013-12-24 18:17:58 -07:00
parent 95e0e465cf
commit 8f8ea60b4f
2 changed files with 8 additions and 6 deletions

View File

@ -1,4 +1,4 @@
package iso
package common
import (
"fmt"
@ -21,9 +21,9 @@ var KeepFileExtensions = []string{".nvram", ".vmdk", ".vmsd", ".vmx", ".vmxf"}
//
// Produces:
// <nothing>
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) {}

View File

@ -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{},
}