Commit e0b05355 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: If interrupted, Ask is disabled

parent dc5d2619
...@@ -49,9 +49,10 @@ type PrefixedUi struct { ...@@ -49,9 +49,10 @@ type PrefixedUi struct {
// The ReaderWriterUi is a UI that writes and reads from standard Go // The ReaderWriterUi is a UI that writes and reads from standard Go
// io.Reader and io.Writer. // io.Reader and io.Writer.
type ReaderWriterUi struct { type ReaderWriterUi struct {
Reader io.Reader Reader io.Reader
Writer io.Writer Writer io.Writer
l sync.Mutex l sync.Mutex
interrupted bool
} }
func (u *ColoredUi) Ask(query string) (string, error) { func (u *ColoredUi) Ask(query string) (string, error) {
...@@ -104,6 +105,10 @@ func (rw *ReaderWriterUi) Ask(query string) (string, error) { ...@@ -104,6 +105,10 @@ func (rw *ReaderWriterUi) Ask(query string) (string, error) {
rw.l.Lock() rw.l.Lock()
defer rw.l.Unlock() defer rw.l.Unlock()
if rw.interrupted {
return "", errors.New("interrupted")
}
sigCh := make(chan os.Signal, 1) sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt) signal.Notify(sigCh, os.Interrupt)
defer signal.Stop(sigCh) defer signal.Stop(sigCh)
...@@ -129,6 +134,7 @@ func (rw *ReaderWriterUi) Ask(query string) (string, error) { ...@@ -129,6 +134,7 @@ func (rw *ReaderWriterUi) Ask(query string) (string, error) {
case line := <-result: case line := <-result:
return line, nil return line, nil
case <-sigCh: case <-sigCh:
rw.interrupted = true
return "", errors.New("interrupted") 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