Skip to content

Commit

Permalink
Merge pull request moby#49244 from thaJeztah/ioutils_deprecations
Browse files Browse the repository at this point in the history
pkg/ioutils: deprecate unused types and functions
  • Loading branch information
AkihiroSuda authored Jan 9, 2025
2 parents 45fe686 + 818a180 commit 00d1b92
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ 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:
Expand Down
6 changes: 5 additions & 1 deletion api/server/router/build/build_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,12 @@ type flusher interface {
Flush()
}

type nopFlusher struct{}

func (f *nopFlusher) Flush() {}

func wrapOutputBufferedUntilRequestRead(rc io.ReadCloser, out io.Writer) (io.ReadCloser, io.Writer) {
var fl flusher = &ioutils.NopFlusher{}
var fl flusher = &nopFlusher{}
if f, ok := out.(flusher); ok {
fl = f
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/ioutils/bytespipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ 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)
Expand All @@ -28,6 +30,8 @@ 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
Expand All @@ -40,6 +44,8 @@ type BytesPipe struct {
// NewBytesPipe 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 {
bp := &BytesPipe{}
bp.buf = append(bp.buf, getBuffer(minCap))
Expand Down
8 changes: 7 additions & 1 deletion pkg/ioutils/writeflusher.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,19 @@ func (wf *WriteFlusher) Close() error {
return nil
}

// nopFlusher represents a type which flush operation is nop.
type nopFlusher struct{}

// Flush is a nop operation.
func (f *nopFlusher) Flush() {}

// NewWriteFlusher returns a new WriteFlusher.
func NewWriteFlusher(w io.Writer) *WriteFlusher {
var fl flusher
if f, ok := w.(flusher); ok {
fl = f
} else {
fl = &NopFlusher{}
fl = &nopFlusher{}
}
return &WriteFlusher{w: w, flusher: fl, closed: make(chan struct{}), flushed: make(chan struct{})}
}
11 changes: 7 additions & 4 deletions pkg/ioutils/writers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ func NopWriteCloser(w io.Writer) io.WriteCloser {
}

// NopFlusher represents a type which flush operation is nop.
type NopFlusher struct{}

// Flush is a nop operation.
func (f *NopFlusher) Flush() {}
//
// Deprecated: NopFlusher is only used internally and will be removed in the next release.
type NopFlusher = nopFlusher

type writeCloserWrapper struct {
io.Writer
Expand Down Expand Up @@ -55,12 +54,16 @@ func NewWriteCloserWrapper(r io.Writer, closer func() error) io.WriteCloser {
// of bytes written to the writer during a "session".
// This can be convenient when write return is masked
// (e.g., json.Encoder.Encode())
//
// Deprecated: this type is no longer used and will be removed in the next release.
type WriteCounter struct {
Count int64
Writer io.Writer
}

// NewWriteCounter returns a new WriteCounter.
//
// Deprecated: this function is no longer used and will be removed in the next release.
func NewWriteCounter(w io.Writer) *WriteCounter {
return &WriteCounter{
Writer: w,
Expand Down

0 comments on commit 00d1b92

Please sign in to comment.