mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-05 03:17:50 +08:00
eval: Introduce (*Port).Fork.
This commit is contained in:
parent
4ff3f771d1
commit
6097cfd76d
|
@ -340,11 +340,7 @@ func (cp *compiler) redir(n *parse.Redir) Op {
|
|||
ec.ports[dst] = &Port{}
|
||||
} else {
|
||||
fd := srcMust.zerothMustNonNegativeInt()
|
||||
ec.ports[dst] = ec.ports[fd]
|
||||
if ec.ports[dst] != nil {
|
||||
ec.ports[dst].CloseFile = false
|
||||
ec.ports[dst].CloseChan = false
|
||||
}
|
||||
ec.ports[dst] = ec.ports[fd].Fork()
|
||||
}
|
||||
} else {
|
||||
f, err := os.OpenFile(src, flag, defaultFileRedirPerm)
|
||||
|
|
|
@ -111,13 +111,12 @@ func NewTopEvalCtx(ev *Evaler, name, text string, ports []*Port) *evalCtx {
|
|||
}
|
||||
}
|
||||
|
||||
// fork returns a modified copy of ec. The ports are copied deeply, with
|
||||
// shouldClose flags reset, and the context is changed to the given value.
|
||||
// Other fields are copied shallowly.
|
||||
// fork returns a modified copy of ec. The ports are forked, and the context is
|
||||
// changed to the given value. Other fields are copied shallowly.
|
||||
func (ec *evalCtx) fork(newContext string) *evalCtx {
|
||||
newPorts := make([]*Port, len(ec.ports))
|
||||
for i, p := range ec.ports {
|
||||
newPorts[i] = &Port{p.File, p.Chan, false, false}
|
||||
newPorts[i] = p.Fork()
|
||||
}
|
||||
return &evalCtx{
|
||||
ec.Evaler,
|
||||
|
|
|
@ -10,7 +10,12 @@ type Port struct {
|
|||
CloseChan bool
|
||||
}
|
||||
|
||||
// close closes a Port.
|
||||
// Fork returns a copy of a Port with the Close* flags unset.
|
||||
func (p *Port) Fork() *Port {
|
||||
return &Port{p.File, p.Chan, false, false}
|
||||
}
|
||||
|
||||
// Close closes a Port.
|
||||
func (p *Port) Close() {
|
||||
if p == nil {
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue
Block a user