mirror of
https://github.com/hashicorp/packer.git
synced 2026-09-19 06:21:41 -04:00
34 lines
639 B
Go
34 lines
639 B
Go
// Copyright IBM Corp. 2024, 2025
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package packer
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
|
|
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
|
)
|
|
|
|
type cmdHook struct {
|
|
hook packersdk.Hook
|
|
client *PluginClient
|
|
}
|
|
|
|
func (c *cmdHook) Run(ctx context.Context, name string, ui packersdk.Ui, comm packersdk.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)
|
|
}
|
|
}
|