Commit 8f8ea60b authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/vmware/common: StepCleanFiles

parent 95e0e465
package iso package common
import ( import (
"fmt" "fmt"
...@@ -21,9 +21,9 @@ var KeepFileExtensions = []string{".nvram", ".vmdk", ".vmsd", ".vmx", ".vmxf"} ...@@ -21,9 +21,9 @@ var KeepFileExtensions = []string{".nvram", ".vmdk", ".vmsd", ".vmx", ".vmxf"}
// //
// Produces: // Produces:
// <nothing> // <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) dir := state.Get("dir").(OutputDir)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
...@@ -49,7 +49,9 @@ func (stepCleanFiles) Run(state multistep.StateBag) multistep.StepAction { ...@@ -49,7 +49,9 @@ func (stepCleanFiles) Run(state multistep.StateBag) multistep.StepAction {
if !keep { if !keep {
ui.Message(fmt.Sprintf("Deleting: %s", path)) ui.Message(fmt.Sprintf("Deleting: %s", path))
if err = dir.Remove(path); err != nil { 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) { if _, serr := os.Stat(path); serr == nil || !os.IsNotExist(serr) {
state.Put("error", err) state.Put("error", err)
return multistep.ActionHalt return multistep.ActionHalt
...@@ -61,4 +63,4 @@ func (stepCleanFiles) Run(state multistep.StateBag) multistep.StepAction { ...@@ -61,4 +63,4 @@ func (stepCleanFiles) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionContinue return multistep.ActionContinue
} }
func (stepCleanFiles) Cleanup(multistep.StateBag) {} func (StepCleanFiles) Cleanup(multistep.StateBag) {}
...@@ -411,7 +411,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -411,7 +411,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&stepUploadTools{}, &stepUploadTools{},
&common.StepProvision{}, &common.StepProvision{},
&stepShutdown{}, &stepShutdown{},
&stepCleanFiles{}, &vmwcommon.StepCleanFiles{},
&stepCleanVMX{}, &stepCleanVMX{},
&stepCompactDisk{}, &stepCompactDisk{},
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment