Merge pull request #1718 from ijc/dial-stdio-npipe-on-windows
dial-stdio: handle connections which lack CloseRead method.
This commit is contained in:
commit
d6a230606c
@ -4,7 +4,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/docker/cli/cli"
|
"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()
|
// flags must be the original top-level command flags, not cmd.Flags()
|
||||||
options.opts.Common.SetDefaultOptions(options.flags)
|
options.opts.Common.SetDefaultOptions(options.flags)
|
||||||
var initopts []command.InitializeOpt
|
err = options.dockerCli.Initialize(options.opts, withPluginClientConn(options.name))
|
||||||
if runtime.GOOS != "windows" {
|
|
||||||
initopts = append(initopts, withPluginClientConn(options.name))
|
|
||||||
}
|
|
||||||
err = options.dockerCli.Initialize(options.opts, initopts...)
|
|
||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package system
|
package system
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"runtime"
|
|
||||||
|
|
||||||
"github.com/docker/cli/cli"
|
"github.com/docker/cli/cli"
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -21,12 +19,8 @@ func NewSystemCommand(dockerCli command.Cli) *cobra.Command {
|
|||||||
NewInfoCommand(dockerCli),
|
NewInfoCommand(dockerCli),
|
||||||
newDiskUsageCommand(dockerCli),
|
newDiskUsageCommand(dockerCli),
|
||||||
newPruneCommand(dockerCli),
|
newPruneCommand(dockerCli),
|
||||||
|
newDialStdioCommand(dockerCli),
|
||||||
)
|
)
|
||||||
if runtime.GOOS != "windows" {
|
|
||||||
cmd.AddCommand(
|
|
||||||
newDialStdioCommand(dockerCli),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
@ -34,10 +34,18 @@ func runDialStdio(dockerCli command.Cli) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to open the raw stream connection")
|
return errors.Wrap(err, "failed to open the raw stream connection")
|
||||||
}
|
}
|
||||||
connHalfCloser, ok := conn.(halfCloser)
|
defer conn.Close()
|
||||||
if !ok {
|
|
||||||
|
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")
|
return errors.New("the raw stream connection does not implement halfCloser")
|
||||||
}
|
}
|
||||||
|
|
||||||
stdin2conn := make(chan error)
|
stdin2conn := make(chan error)
|
||||||
conn2stdout := make(chan error)
|
conn2stdout := make(chan error)
|
||||||
go func() {
|
go func() {
|
||||||
@ -90,6 +98,19 @@ type halfCloser interface {
|
|||||||
halfWriteCloser
|
halfWriteCloser
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type halfReadWriteCloser interface {
|
||||||
|
io.Reader
|
||||||
|
halfWriteCloser
|
||||||
|
}
|
||||||
|
|
||||||
|
type nopCloseReader struct {
|
||||||
|
halfReadWriteCloser
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *nopCloseReader) CloseRead() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type halfReadCloserWrapper struct {
|
type halfReadCloserWrapper struct {
|
||||||
io.ReadCloser
|
io.ReadCloser
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user