packer: If interrupted, Ask is disabled
This commit is contained in:
parent
dc5d261994
commit
e0b05355c3
12
packer/ui.go
12
packer/ui.go
@ -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) {
|
|||||||
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) {
|
|||||||
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")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user