Commit e0b05355 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: If interrupted, Ask is disabled

parent dc5d2619
......@@ -52,6 +52,7 @@ type ReaderWriterUi struct {
Reader io.Reader
Writer io.Writer
l sync.Mutex
interrupted bool
}
func (u *ColoredUi) Ask(query string) (string, error) {
......@@ -104,6 +105,10 @@ func (rw *ReaderWriterUi) Ask(query string) (string, error) {
rw.l.Lock()
defer rw.l.Unlock()
if rw.interrupted {
return "", errors.New("interrupted")
}
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt)
defer signal.Stop(sigCh)
......@@ -129,6 +134,7 @@ func (rw *ReaderWriterUi) Ask(query string) (string, error) {
case line := <-result:
return line, nil
case <-sigCh:
rw.interrupted = true
return "", errors.New("interrupted")
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment