Skip to content

Commit 9c25614

Browse files
authored
Merge pull request #6181 from thaJeztah/fork_readCloserWrapper
remove uses of github.com/docker/docker/pkg/ioutils ReadCloserWrapper
2 parents bc01f84 + 3600ebc commit 9c25614

File tree

7 files changed

+41
-293
lines changed

7 files changed

+41
-293
lines changed

cli/command/container/hijack.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
"github.com/docker/cli/cli/command"
1111
"github.com/docker/docker/api/types"
12-
"github.com/docker/docker/pkg/ioutils"
1312
"github.com/docker/docker/pkg/stdcopy"
1413
"github.com/moby/term"
1514
"github.com/sirupsen/logrus"
@@ -19,6 +18,18 @@ import (
1918
// TODO: This could be moved to `pkg/term`.
2019
var defaultEscapeKeys = []byte{16, 17}
2120

21+
// readCloserWrapper wraps an io.Reader, and implements an io.ReadCloser
22+
// It calls the given callback function when closed.
23+
type readCloserWrapper struct {
24+
io.Reader
25+
closer func() error
26+
}
27+
28+
// Close calls back the passed closer function
29+
func (r *readCloserWrapper) Close() error {
30+
return r.closer()
31+
}
32+
2233
// A hijackedIOStreamer handles copying input to and output from streams to the
2334
// connection.
2435
type hijackedIOStreamer struct {
@@ -100,7 +111,10 @@ func (h *hijackedIOStreamer) setupInput() (restore func(), err error) {
100111
}
101112
}
102113

103-
h.inputStream = ioutils.NewReadCloserWrapper(term.NewEscapeProxy(h.inputStream, escapeKeys), h.inputStream.Close)
114+
h.inputStream = &readCloserWrapper{
115+
Reader: term.NewEscapeProxy(h.inputStream, escapeKeys),
116+
closer: h.inputStream.Close,
117+
}
104118

105119
return restore, nil
106120
}

cli/command/image/build/context.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"time"
1818

1919
"github.com/docker/docker/builder/remotecontext/git"
20-
"github.com/docker/docker/pkg/ioutils"
2120
"github.com/docker/docker/pkg/progress"
2221
"github.com/docker/docker/pkg/streamformatter"
2322
"github.com/moby/go-archive"
@@ -109,7 +108,7 @@ func DetectArchiveReader(input io.ReadCloser) (rc io.ReadCloser, isArchive bool,
109108
return nil, false, errors.Errorf("failed to peek context header from STDIN: %v", err)
110109
}
111110

112-
return ioutils.NewReadCloserWrapper(buf, func() error { return input.Close() }), IsArchive(magic), nil
111+
return newReadCloserWrapper(buf, func() error { return input.Close() }), IsArchive(magic), nil
113112
}
114113

115114
// WriteTempDockerfile writes a Dockerfile stream to a temporary file with a
@@ -170,7 +169,7 @@ func GetContextFromReader(rc io.ReadCloser, dockerfileName string) (out io.ReadC
170169
return nil, "", err
171170
}
172171

173-
return ioutils.NewReadCloserWrapper(tarArchive, func() error {
172+
return newReadCloserWrapper(tarArchive, func() error {
174173
err := tarArchive.Close()
175174
os.RemoveAll(dockerfileDir)
176175
return err
@@ -228,7 +227,7 @@ func GetContextFromURL(out io.Writer, remoteURL, dockerfileName string) (io.Read
228227
// Pass the response body through a progress reader.
229228
progReader := progress.NewProgressReader(response.Body, progressOutput, response.ContentLength, "", "Downloading build context from remote url: "+remoteURL)
230229

231-
return GetContextFromReader(ioutils.NewReadCloserWrapper(progReader, func() error { return response.Body.Close() }), dockerfileName)
230+
return GetContextFromReader(newReadCloserWrapper(progReader, func() error { return response.Body.Close() }), dockerfileName)
232231
}
233232

234233
// getWithStatusError does an http.Get() and returns an error if the
@@ -454,3 +453,25 @@ func Compress(buildCtx io.ReadCloser) (io.ReadCloser, error) {
454453

455454
return pipeReader, nil
456455
}
456+
457+
// readCloserWrapper wraps an io.Reader, and implements an io.ReadCloser
458+
// It calls the given callback function when closed. It should be constructed
459+
// with [newReadCloserWrapper].
460+
type readCloserWrapper struct {
461+
io.Reader
462+
closer func() error
463+
}
464+
465+
// Close calls back the passed closer function
466+
func (r *readCloserWrapper) Close() error {
467+
return r.closer()
468+
}
469+
470+
// newReadCloserWrapper wraps an io.Reader, and implements an io.ReadCloser.
471+
// It calls the given callback function when closed.
472+
func newReadCloserWrapper(r io.Reader, closer func() error) io.ReadCloser {
473+
return &readCloserWrapper{
474+
Reader: r,
475+
closer: closer,
476+
}
477+
}

vendor/github.com/docker/docker/pkg/ioutils/fswriters_deprecated.go

Lines changed: 0 additions & 44 deletions
This file was deleted.

vendor/github.com/docker/docker/pkg/ioutils/readers.go

Lines changed: 0 additions & 118 deletions
This file was deleted.

vendor/github.com/docker/docker/pkg/ioutils/writeflusher.go

Lines changed: 0 additions & 96 deletions
This file was deleted.

vendor/github.com/docker/docker/pkg/ioutils/writers.go

Lines changed: 0 additions & 28 deletions
This file was deleted.

vendor/modules.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ github.com/docker/docker/client
9595
github.com/docker/docker/internal/lazyregexp
9696
github.com/docker/docker/internal/multierror
9797
github.com/docker/docker/pkg/homedir
98-
github.com/docker/docker/pkg/ioutils
9998
github.com/docker/docker/pkg/jsonmessage
10099
github.com/docker/docker/pkg/process
101100
github.com/docker/docker/pkg/progress

0 commit comments

Comments
 (0)