2013-07-31 01:25:33 -04:00
|
|
|
package chroot
|
|
|
|
|
|
|
|
import (
|
2018-01-22 18:32:33 -05:00
|
|
|
"context"
|
2013-07-31 01:25:33 -04:00
|
|
|
"fmt"
|
2018-01-22 18:32:33 -05:00
|
|
|
"log"
|
|
|
|
|
2018-01-19 19:18:44 -05:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2020-11-12 17:44:02 -05:00
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/chroot"
|
2013-07-31 01:25:33 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// StepEarlyUnflock unlocks the flock.
|
|
|
|
type StepEarlyUnflock struct{}
|
|
|
|
|
2019-03-29 11:50:02 -04:00
|
|
|
func (s *StepEarlyUnflock) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
2019-10-24 00:21:08 -04:00
|
|
|
cleanup := state.Get("flock_cleanup").(chroot.Cleanup)
|
2013-08-31 15:58:55 -04:00
|
|
|
ui := state.Get("ui").(packer.Ui)
|
2013-07-31 01:25:33 -04:00
|
|
|
|
|
|
|
log.Println("Unlocking file lock...")
|
|
|
|
if err := cleanup.CleanupFunc(state); err != nil {
|
|
|
|
err := fmt.Errorf("Error unlocking file lock: %s", err)
|
2013-08-31 15:58:55 -04:00
|
|
|
state.Put("error", err)
|
2013-07-31 01:25:33 -04:00
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2013-08-31 15:58:55 -04:00
|
|
|
func (s *StepEarlyUnflock) Cleanup(state multistep.StateBag) {}
|