2013-06-18 16:49:07 -04:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2013-06-18 16:49:07 -04:00
|
|
|
"log"
|
|
|
|
)
|
|
|
|
|
|
|
|
type cmdPostProcessor struct {
|
|
|
|
p packer.PostProcessor
|
|
|
|
client *Client
|
|
|
|
}
|
|
|
|
|
2013-07-01 17:59:23 -04:00
|
|
|
func (c *cmdPostProcessor) Configure(config ...interface{}) error {
|
2013-06-18 16:49:07 -04:00
|
|
|
defer func() {
|
|
|
|
r := recover()
|
|
|
|
c.checkExit(r, nil)
|
|
|
|
}()
|
|
|
|
|
2013-07-01 17:59:23 -04:00
|
|
|
return c.p.Configure(config...)
|
2013-06-18 16:49:07 -04:00
|
|
|
}
|
|
|
|
|
2013-07-01 14:30:39 -04:00
|
|
|
func (c *cmdPostProcessor) PostProcess(ui packer.Ui, a packer.Artifact) (packer.Artifact, bool, error) {
|
2013-06-18 16:49:07 -04:00
|
|
|
defer func() {
|
|
|
|
r := recover()
|
|
|
|
c.checkExit(r, nil)
|
|
|
|
}()
|
|
|
|
|
2013-06-18 23:38:21 -04:00
|
|
|
return c.p.PostProcess(ui, a)
|
2013-06-18 16:49:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *cmdPostProcessor) checkExit(p interface{}, cb func()) {
|
2015-05-29 14:30:56 -04:00
|
|
|
if c.client.Exited() && cb != nil {
|
2013-06-18 16:49:07 -04:00
|
|
|
cb()
|
2013-08-20 02:38:22 -04:00
|
|
|
} else if p != nil && !Killed {
|
2013-06-18 16:49:07 -04:00
|
|
|
log.Panic(p)
|
|
|
|
}
|
|
|
|
}
|