Adrien Delorme 829851fc8a change hooks to be passed a context for cancellation
we have to as it is what calls our provisioners
2019-04-03 15:55:54 +02:00

31 lines
531 B
Go

package plugin
import (
"context"
"log"
"github.com/hashicorp/packer/packer"
)
type cmdHook struct {
hook packer.Hook
client *Client
}
func (c *cmdHook) Run(ctx context.Context, name string, ui packer.Ui, comm packer.Communicator, data interface{}) error {
defer func() {
r := recover()
c.checkExit(r, nil)
}()
return c.hook.Run(ctx, name, ui, comm, data)
}
func (c *cmdHook) checkExit(p interface{}, cb func()) {
if c.client.Exited() && cb != nil {
cb()
} else if p != nil && !Killed {
log.Panic(p)
}
}