Skip to content

Commit d6a2306

Browse files
authored
Merge pull request #1718 from ijc/dial-stdio-npipe-on-windows
dial-stdio: handle connections which lack CloseRead method.
2 parents 81ac432 + 0449ad8 commit d6a2306

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

cli-plugins/plugin/plugin.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"encoding/json"
55
"fmt"
66
"os"
7-
"runtime"
87
"sync"
98

109
"github.com/docker/cli/cli"
@@ -75,11 +74,7 @@ func PersistentPreRunE(cmd *cobra.Command, args []string) error {
7574
}
7675
// flags must be the original top-level command flags, not cmd.Flags()
7776
options.opts.Common.SetDefaultOptions(options.flags)
78-
var initopts []command.InitializeOpt
79-
if runtime.GOOS != "windows" {
80-
initopts = append(initopts, withPluginClientConn(options.name))
81-
}
82-
err = options.dockerCli.Initialize(options.opts, initopts...)
77+
err = options.dockerCli.Initialize(options.opts, withPluginClientConn(options.name))
8378
})
8479
return err
8580
}

cli/command/system/cmd.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package system
22

33
import (
4-
"runtime"
5-
64
"github.com/docker/cli/cli"
75
"github.com/docker/cli/cli/command"
86
"github.com/spf13/cobra"
@@ -21,12 +19,8 @@ func NewSystemCommand(dockerCli command.Cli) *cobra.Command {
2119
NewInfoCommand(dockerCli),
2220
newDiskUsageCommand(dockerCli),
2321
newPruneCommand(dockerCli),
22+
newDialStdioCommand(dockerCli),
2423
)
25-
if runtime.GOOS != "windows" {
26-
cmd.AddCommand(
27-
newDialStdioCommand(dockerCli),
28-
)
29-
}
3024

3125
return cmd
3226
}

cli/command/system/dial_stdio.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,18 @@ func runDialStdio(dockerCli command.Cli) error {
3434
if err != nil {
3535
return errors.Wrap(err, "failed to open the raw stream connection")
3636
}
37-
connHalfCloser, ok := conn.(halfCloser)
38-
if !ok {
37+
defer conn.Close()
38+
39+
var connHalfCloser halfCloser
40+
switch t := conn.(type) {
41+
case halfCloser:
42+
connHalfCloser = t
43+
case halfReadWriteCloser:
44+
connHalfCloser = &nopCloseReader{t}
45+
default:
3946
return errors.New("the raw stream connection does not implement halfCloser")
4047
}
48+
4149
stdin2conn := make(chan error)
4250
conn2stdout := make(chan error)
4351
go func() {
@@ -90,6 +98,19 @@ type halfCloser interface {
9098
halfWriteCloser
9199
}
92100

101+
type halfReadWriteCloser interface {
102+
io.Reader
103+
halfWriteCloser
104+
}
105+
106+
type nopCloseReader struct {
107+
halfReadWriteCloser
108+
}
109+
110+
func (x *nopCloseReader) CloseRead() error {
111+
return nil
112+
}
113+
93114
type halfReadCloserWrapper struct {
94115
io.ReadCloser
95116
}

0 commit comments

Comments
 (0)