packer-cn/packer/plugin/builder.go

47 lines
756 B
Go
Raw Normal View History

package plugin
import (
"github.com/mitchellh/packer/packer"
"log"
)
type cmdBuilder struct {
builder packer.Builder
client *Client
}
func (b *cmdBuilder) Prepare(config interface{}) error {
defer func() {
r := recover()
b.checkExit(r, nil)
}()
return b.builder.Prepare(config)
}
2013-06-10 01:00:47 -04:00
func (b *cmdBuilder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) packer.Artifact {
defer func() {
r := recover()
b.checkExit(r, nil)
}()
2013-06-10 01:00:47 -04:00
return b.builder.Run(ui, hook, cache)
}
func (b *cmdBuilder) Cancel() {
defer func() {
r := recover()
b.checkExit(r, nil)
}()
b.builder.Cancel()
}
func (c *cmdBuilder) checkExit(p interface{}, cb func()) {
if c.client.Exited() && cb != nil {
cb()
} else if p != nil {
log.Panic(p)
}
}