cio.copyIO: refactor to use cio.Close() (windows)
Use the existing `.Close()` method instead of implementing the same logic in this function. The defer sets `cios` to `nil` if an error occurred to preserve the existing behavior. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
219fa3d0a5
commit
7a468a3f3f
@ -43,19 +43,11 @@ func NewFIFOSetInDir(_, id string, terminal bool) (*FIFOSet, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func copyIO(fifos *FIFOSet, ioset *Streams) (_ *cio, retErr error) {
|
func copyIO(fifos *FIFOSet, ioset *Streams) (_ *cio, retErr error) {
|
||||||
var (
|
cios := &cio{config: fifos.Config}
|
||||||
set []io.Closer
|
|
||||||
)
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if retErr == nil {
|
if retErr != nil {
|
||||||
return
|
_ = cios.Close()
|
||||||
}
|
|
||||||
for _, closer := range set {
|
|
||||||
if closer == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
_ = closer.Close()
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -64,7 +56,7 @@ func copyIO(fifos *FIFOSet, ioset *Streams) (_ *cio, retErr error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to create stdin pipe %s", fifos.Stdin)
|
return nil, errors.Wrapf(err, "failed to create stdin pipe %s", fifos.Stdin)
|
||||||
}
|
}
|
||||||
set = append(set, l)
|
cios.closers = append(cios.closers, l)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
c, err := l.Accept()
|
c, err := l.Accept()
|
||||||
@ -87,7 +79,7 @@ func copyIO(fifos *FIFOSet, ioset *Streams) (_ *cio, retErr error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to create stdout pipe %s", fifos.Stdout)
|
return nil, errors.Wrapf(err, "failed to create stdout pipe %s", fifos.Stdout)
|
||||||
}
|
}
|
||||||
set = append(set, l)
|
cios.closers = append(cios.closers, l)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
c, err := l.Accept()
|
c, err := l.Accept()
|
||||||
@ -110,7 +102,7 @@ func copyIO(fifos *FIFOSet, ioset *Streams) (_ *cio, retErr error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "failed to create stderr pipe %s", fifos.Stderr)
|
return nil, errors.Wrapf(err, "failed to create stderr pipe %s", fifos.Stderr)
|
||||||
}
|
}
|
||||||
set = append(set, l)
|
cios.closers = append(cios.closers, l)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
c, err := l.Accept()
|
c, err := l.Accept()
|
||||||
@ -128,7 +120,7 @@ func copyIO(fifos *FIFOSet, ioset *Streams) (_ *cio, retErr error) {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
return &cio{config: fifos.Config, closers: set}, nil
|
return cios, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDirectIO returns an IO implementation that exposes the IO streams as io.ReadCloser
|
// NewDirectIO returns an IO implementation that exposes the IO streams as io.ReadCloser
|
||||||
|
Loading…
Reference in New Issue
Block a user