mirror of
https://github.com/containers/podman.git
synced 2026-03-18 14:46:58 -04:00
Bumps [github.com/vbauerster/mpb/v7](https://github.com/vbauerster/mpb) from 7.5.2 to 7.5.3. - [Release notes](https://github.com/vbauerster/mpb/releases) - [Commits](https://github.com/vbauerster/mpb/compare/v7.5.2...v7.5.3) --- updated-dependencies: - dependency-name: github.com/vbauerster/mpb/v7 dependency-type: direct:production update-type: version-update:semver-patch ... Also bump the go module to 1.17 to be able to compile the new code. Given containers/common and others already require go 1.17+ we're safe to go. Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
80 lines
1.3 KiB
Go
80 lines
1.3 KiB
Go
package mpb
|
|
|
|
import (
|
|
"io"
|
|
"time"
|
|
)
|
|
|
|
type proxyReader struct {
|
|
io.ReadCloser
|
|
bar *Bar
|
|
}
|
|
|
|
func (x proxyReader) Read(p []byte) (int, error) {
|
|
n, err := x.ReadCloser.Read(p)
|
|
x.bar.IncrBy(n)
|
|
return n, err
|
|
}
|
|
|
|
type proxyWriterTo struct {
|
|
proxyReader
|
|
wt io.WriterTo
|
|
}
|
|
|
|
func (x proxyWriterTo) WriteTo(w io.Writer) (int64, error) {
|
|
n, err := x.wt.WriteTo(w)
|
|
x.bar.IncrInt64(n)
|
|
return n, err
|
|
}
|
|
|
|
type ewmaProxyReader struct {
|
|
proxyReader
|
|
}
|
|
|
|
func (x ewmaProxyReader) Read(p []byte) (int, error) {
|
|
start := time.Now()
|
|
n, err := x.proxyReader.Read(p)
|
|
if n > 0 {
|
|
x.bar.DecoratorEwmaUpdate(time.Since(start))
|
|
}
|
|
return n, err
|
|
}
|
|
|
|
type ewmaProxyWriterTo struct {
|
|
ewmaProxyReader
|
|
wt proxyWriterTo
|
|
}
|
|
|
|
func (x ewmaProxyWriterTo) WriteTo(w io.Writer) (int64, error) {
|
|
start := time.Now()
|
|
n, err := x.wt.WriteTo(w)
|
|
if n > 0 {
|
|
x.bar.DecoratorEwmaUpdate(time.Since(start))
|
|
}
|
|
return n, err
|
|
}
|
|
|
|
func (b *Bar) newProxyReader(r io.Reader) (rc io.ReadCloser) {
|
|
pr := proxyReader{toReadCloser(r), b}
|
|
if wt, ok := r.(io.WriterTo); ok {
|
|
pw := proxyWriterTo{pr, wt}
|
|
if b.hasEwma {
|
|
rc = ewmaProxyWriterTo{ewmaProxyReader{pr}, pw}
|
|
} else {
|
|
rc = pw
|
|
}
|
|
} else if b.hasEwma {
|
|
rc = ewmaProxyReader{pr}
|
|
} else {
|
|
rc = pr
|
|
}
|
|
return rc
|
|
}
|
|
|
|
func toReadCloser(r io.Reader) io.ReadCloser {
|
|
if rc, ok := r.(io.ReadCloser); ok {
|
|
return rc
|
|
}
|
|
return io.NopCloser(r)
|
|
}
|