packer-cn/packer/plugin/post_processor.go

40 lines
723 B
Go
Raw Normal View History

2013-06-18 16:49:07 -04:00
package plugin
import (
2019-03-22 09:56:02 -04:00
"context"
2013-06-18 16:49:07 -04:00
"log"
2018-01-22 20:21:10 -05:00
"github.com/hashicorp/packer/packer"
2013-06-18 16:49:07 -04:00
)
type cmdPostProcessor struct {
p packer.PostProcessor
client *Client
}
func (c *cmdPostProcessor) Configure(config ...interface{}) error {
2013-06-18 16:49:07 -04:00
defer func() {
r := recover()
c.checkExit(r, nil)
}()
return c.p.Configure(config...)
2013-06-18 16:49:07 -04:00
}
func (c *cmdPostProcessor) PostProcess(ctx context.Context, ui packer.Ui, a packer.Artifact) (packer.Artifact, bool, bool, error) {
2013-06-18 16:49:07 -04:00
defer func() {
r := recover()
c.checkExit(r, nil)
}()
2019-03-22 09:56:02 -04:00
return c.p.PostProcess(ctx, ui, a)
2013-06-18 16:49:07 -04:00
}
func (c *cmdPostProcessor) checkExit(p interface{}, cb func()) {
if c.client.Exited() && cb != nil {
2013-06-18 16:49:07 -04:00
cb()
} else if p != nil && !Killed {
2013-06-18 16:49:07 -04:00
log.Panic(p)
}
}