mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-11-21 20:35:11 +00:00
Fix reader regression (#4070)
This commit is contained in:
parent
19495eb9bb
commit
acdf265d7a
@ -24,6 +24,7 @@ type Reader struct {
|
|||||||
event int32
|
event int32
|
||||||
finChan chan bool
|
finChan chan bool
|
||||||
mutex sync.Mutex
|
mutex sync.Mutex
|
||||||
|
killed bool
|
||||||
termFunc func()
|
termFunc func()
|
||||||
command *string
|
command *string
|
||||||
wait bool
|
wait bool
|
||||||
@ -39,6 +40,7 @@ func NewReader(pusher func([]byte) bool, eventBox *util.EventBox, executor *util
|
|||||||
int32(EvtReady),
|
int32(EvtReady),
|
||||||
make(chan bool, 1),
|
make(chan bool, 1),
|
||||||
sync.Mutex{},
|
sync.Mutex{},
|
||||||
|
false,
|
||||||
func() { os.Stdin.Close() },
|
func() { os.Stdin.Close() },
|
||||||
nil,
|
nil,
|
||||||
wait}
|
wait}
|
||||||
@ -68,10 +70,6 @@ func (r *Reader) startEventPoller() {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reader) wasKilled() bool {
|
|
||||||
return r.termFunc == nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *Reader) fin(success bool) {
|
func (r *Reader) fin(success bool) {
|
||||||
atomic.StoreInt32(&r.event, int32(EvtReadFin))
|
atomic.StoreInt32(&r.event, int32(EvtReadFin))
|
||||||
if r.wait {
|
if r.wait {
|
||||||
@ -80,7 +78,7 @@ func (r *Reader) fin(success bool) {
|
|||||||
|
|
||||||
r.mutex.Lock()
|
r.mutex.Lock()
|
||||||
ret := r.command
|
ret := r.command
|
||||||
if success || r.wasKilled() {
|
if success || r.killed {
|
||||||
ret = nil
|
ret = nil
|
||||||
}
|
}
|
||||||
r.mutex.Unlock()
|
r.mutex.Unlock()
|
||||||
@ -90,6 +88,7 @@ func (r *Reader) fin(success bool) {
|
|||||||
|
|
||||||
func (r *Reader) terminate() {
|
func (r *Reader) terminate() {
|
||||||
r.mutex.Lock()
|
r.mutex.Lock()
|
||||||
|
r.killed = true
|
||||||
if r.termFunc != nil {
|
if r.termFunc != nil {
|
||||||
r.termFunc()
|
r.termFunc()
|
||||||
r.termFunc = nil
|
r.termFunc = nil
|
||||||
@ -297,7 +296,7 @@ func (r *Reader) readFiles(root string, opts walkerOpts, ignores []string) bool
|
|||||||
}
|
}
|
||||||
r.mutex.Lock()
|
r.mutex.Lock()
|
||||||
defer r.mutex.Unlock()
|
defer r.mutex.Unlock()
|
||||||
if r.wasKilled() {
|
if r.killed {
|
||||||
return context.Canceled
|
return context.Canceled
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -308,6 +307,7 @@ func (r *Reader) readFiles(root string, opts walkerOpts, ignores []string) bool
|
|||||||
func (r *Reader) readFromCommand(command string, environ []string, signalReady func()) bool {
|
func (r *Reader) readFromCommand(command string, environ []string, signalReady func()) bool {
|
||||||
r.mutex.Lock()
|
r.mutex.Lock()
|
||||||
|
|
||||||
|
r.killed = false
|
||||||
r.termFunc = nil
|
r.termFunc = nil
|
||||||
r.command = &command
|
r.command = &command
|
||||||
exec := r.executor.ExecCommand(command, true)
|
exec := r.executor.ExecCommand(command, true)
|
||||||
@ -316,6 +316,7 @@ func (r *Reader) readFromCommand(command string, environ []string, signalReady f
|
|||||||
}
|
}
|
||||||
execOut, err := exec.StdoutPipe()
|
execOut, err := exec.StdoutPipe()
|
||||||
if err != nil || exec.Start() != nil {
|
if err != nil || exec.Start() != nil {
|
||||||
|
signalReady()
|
||||||
r.mutex.Unlock()
|
r.mutex.Unlock()
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user