Merge pull request #1718 from ijc/dial-stdio-npipe-on-windows

dial-stdio: handle connections which lack CloseRead method.
This commit is contained in:
Sebastiaan van Stijn 2019-03-13 11:49:25 +01:00 committed by GitHub
commit d6a230606c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 15 deletions

View File

@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"os"
"runtime"
"sync"
"github.com/docker/cli/cli"
@ -75,11 +74,7 @@ func PersistentPreRunE(cmd *cobra.Command, args []string) error {
}
// flags must be the original top-level command flags, not cmd.Flags()
options.opts.Common.SetDefaultOptions(options.flags)
var initopts []command.InitializeOpt
if runtime.GOOS != "windows" {
initopts = append(initopts, withPluginClientConn(options.name))
}
err = options.dockerCli.Initialize(options.opts, initopts...)
err = options.dockerCli.Initialize(options.opts, withPluginClientConn(options.name))
})
return err
}

View File

@ -1,8 +1,6 @@
package system
import (
"runtime"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/spf13/cobra"
@ -21,12 +19,8 @@ func NewSystemCommand(dockerCli command.Cli) *cobra.Command {
NewInfoCommand(dockerCli),
newDiskUsageCommand(dockerCli),
newPruneCommand(dockerCli),
newDialStdioCommand(dockerCli),
)
if runtime.GOOS != "windows" {
cmd.AddCommand(
newDialStdioCommand(dockerCli),
)
}
return cmd
}

View File

@ -34,10 +34,18 @@ func runDialStdio(dockerCli command.Cli) error {
if err != nil {
return errors.Wrap(err, "failed to open the raw stream connection")
}
connHalfCloser, ok := conn.(halfCloser)
if !ok {
defer conn.Close()
var connHalfCloser halfCloser
switch t := conn.(type) {
case halfCloser:
connHalfCloser = t
case halfReadWriteCloser:
connHalfCloser = &nopCloseReader{t}
default:
return errors.New("the raw stream connection does not implement halfCloser")
}
stdin2conn := make(chan error)
conn2stdout := make(chan error)
go func() {
@ -90,6 +98,19 @@ type halfCloser interface {
halfWriteCloser
}
type halfReadWriteCloser interface {
io.Reader
halfWriteCloser
}
type nopCloseReader struct {
halfReadWriteCloser
}
func (x *nopCloseReader) CloseRead() error {
return nil
}
type halfReadCloserWrapper struct {
io.ReadCloser
}