diff --git a/.golangci.yml b/.golangci.yml index 0e8f82b543..ec9005be92 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -156,12 +156,6 @@ issues: linters: - staticcheck - # FIXME temporarily suppress these until they are moved internal to container/streams. - - text: "SA1019: ioutils\\.(ErrClosed|BytesPipe|NewBytesPipe)" - path: "container/stream/" - linters: - - staticcheck - - text: "ineffectual assignment to ctx" source: "ctx[, ].*=.*\\(ctx[,)]" linters: diff --git a/pkg/ioutils/buffer.go b/container/stream/bytespipe/buffer.go similarity index 92% rename from pkg/ioutils/buffer.go rename to container/stream/bytespipe/buffer.go index 466f79294b..3beae1350f 100644 --- a/pkg/ioutils/buffer.go +++ b/container/stream/bytespipe/buffer.go @@ -1,4 +1,4 @@ -package ioutils // import "github.com/docker/docker/pkg/ioutils" +package bytespipe import ( "errors" diff --git a/pkg/ioutils/buffer_test.go b/container/stream/bytespipe/buffer_test.go similarity index 97% rename from pkg/ioutils/buffer_test.go rename to container/stream/bytespipe/buffer_test.go index aa75bab48a..2a849029ce 100644 --- a/pkg/ioutils/buffer_test.go +++ b/container/stream/bytespipe/buffer_test.go @@ -1,4 +1,4 @@ -package ioutils // import "github.com/docker/docker/pkg/ioutils" +package bytespipe import ( "bytes" diff --git a/pkg/ioutils/bytespipe.go b/container/stream/bytespipe/bytespipe.go similarity index 90% rename from pkg/ioutils/bytespipe.go rename to container/stream/bytespipe/bytespipe.go index 85450bf6b3..60390fdf71 100644 --- a/pkg/ioutils/bytespipe.go +++ b/container/stream/bytespipe/bytespipe.go @@ -1,4 +1,4 @@ -package ioutils // import "github.com/docker/docker/pkg/ioutils" +package bytespipe import ( "errors" @@ -18,8 +18,6 @@ const blockThreshold = 1e6 var ( // ErrClosed is returned when Write is called on a closed BytesPipe. - // - // Deprecated: this type is only used internally, and will be removed in the next release. ErrClosed = errors.New("write to closed BytesPipe") bufPools = make(map[int]*sync.Pool) @@ -30,8 +28,6 @@ var ( // All written data may be read at most once. Also, BytesPipe allocates // and releases new byte slices to adjust to current needs, so the buffer // won't be overgrown after peak loads. -// -// Deprecated: this type is only used internally, and will be removed in the next release. type BytesPipe struct { mu sync.Mutex wait *sync.Cond @@ -41,12 +37,10 @@ type BytesPipe struct { readBlock bool // check read BytesPipe is Wait() or not } -// NewBytesPipe creates new BytesPipe, initialized by specified slice. +// New creates new BytesPipe, initialized by specified slice. // If buf is nil, then it will be initialized with slice which cap is 64. // buf will be adjusted in a way that len(buf) == 0, cap(buf) == cap(buf). -// -// Deprecated: this function is only used internally, and will be removed in the next release. -func NewBytesPipe() *BytesPipe { +func New() *BytesPipe { bp := &BytesPipe{} bp.buf = append(bp.buf, getBuffer(minCap)) bp.wait = sync.NewCond(&bp.mu) diff --git a/pkg/ioutils/bytespipe_test.go b/container/stream/bytespipe/bytespipe_test.go similarity index 95% rename from pkg/ioutils/bytespipe_test.go rename to container/stream/bytespipe/bytespipe_test.go index 31197b6529..58a71c574f 100644 --- a/pkg/ioutils/bytespipe_test.go +++ b/container/stream/bytespipe/bytespipe_test.go @@ -1,4 +1,4 @@ -package ioutils // import "github.com/docker/docker/pkg/ioutils" +package bytespipe import ( "crypto/sha256" @@ -9,7 +9,7 @@ import ( ) func TestBytesPipeRead(t *testing.T) { - buf := NewBytesPipe() + buf := New() _, _ = buf.Write([]byte("12")) _, _ = buf.Write([]byte("34")) _, _ = buf.Write([]byte("56")) @@ -49,7 +49,7 @@ func TestBytesPipeRead(t *testing.T) { } func TestBytesPipeWrite(t *testing.T) { - buf := NewBytesPipe() + buf := New() _, _ = buf.Write([]byte("12")) _, _ = buf.Write([]byte("34")) _, _ = buf.Write([]byte("56")) @@ -62,7 +62,7 @@ func TestBytesPipeWrite(t *testing.T) { // Regression test for #41941. func TestBytesPipeDeadlock(t *testing.T) { - bp := NewBytesPipe() + bp := New() bp.buf = []*fixedBuffer{getBuffer(blockThreshold)} rd := make(chan error) @@ -145,7 +145,7 @@ func TestBytesPipeWriteRandomChunks(t *testing.T) { expected := hex.EncodeToString(hash.Sum(nil)) // write/read through buffer - buf := NewBytesPipe() + buf := New() hash.Reset() done := make(chan struct{}) @@ -186,7 +186,7 @@ func BenchmarkBytesPipeWrite(b *testing.B) { testData := []byte("pretty short line, because why not?") for i := 0; i < b.N; i++ { readBuf := make([]byte, 1024) - buf := NewBytesPipe() + buf := New() go func() { var err error for err == nil { @@ -205,7 +205,7 @@ func BenchmarkBytesPipeRead(b *testing.B) { rd := make([]byte, 512) for i := 0; i < b.N; i++ { b.StopTimer() - buf := NewBytesPipe() + buf := New() for j := 0; j < 500; j++ { _, _ = buf.Write(make([]byte, 1024)) } diff --git a/container/stream/streams.go b/container/stream/streams.go index 280cafe279..371006b64e 100644 --- a/container/stream/streams.go +++ b/container/stream/streams.go @@ -9,6 +9,7 @@ import ( "github.com/containerd/containerd/cio" "github.com/containerd/log" + "github.com/docker/docker/container/stream/bytespipe" "github.com/docker/docker/pkg/ioutils" "github.com/docker/docker/pkg/pools" ) @@ -64,7 +65,7 @@ func (c *Config) StdinPipe() io.WriteCloser { // It adds this new out pipe to the Stdout broadcaster. // This will block stdout if unconsumed. func (c *Config) StdoutPipe() io.ReadCloser { - bytesPipe := ioutils.NewBytesPipe() + bytesPipe := bytespipe.New() c.stdout.Add(bytesPipe) return bytesPipe } @@ -73,7 +74,7 @@ func (c *Config) StdoutPipe() io.ReadCloser { // It adds this new err pipe to the Stderr broadcaster. // This will block stderr if unconsumed. func (c *Config) StderrPipe() io.ReadCloser { - bytesPipe := ioutils.NewBytesPipe() + bytesPipe := bytespipe.New() c.stderr.Add(bytesPipe) return bytesPipe }