mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 02:33:34 +00:00
vendor update for E2E framework
Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
19
vendor/k8s.io/utils/io/consistentread.go → vendor/k8s.io/utils/io/read.go
generated
vendored
19
vendor/k8s.io/utils/io/consistentread.go → vendor/k8s.io/utils/io/read.go
generated
vendored
@ -18,10 +18,15 @@ package io
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
// ErrLimitReached means that the read limit is reached.
|
||||
var ErrLimitReached = errors.New("the read limit is reached")
|
||||
|
||||
// ConsistentRead repeatedly reads a file until it gets the same content twice.
|
||||
// This is useful when reading files in /proc that are larger than page size
|
||||
// and kernel may modify them between individual read() syscalls.
|
||||
@ -53,3 +58,17 @@ func consistentReadSync(filename string, attempts int, sync func(int)) ([]byte,
|
||||
}
|
||||
return nil, fmt.Errorf("could not get consistent content of %s after %d attempts", filename, attempts)
|
||||
}
|
||||
|
||||
// ReadAtMost reads up to `limit` bytes from `r`, and reports an error
|
||||
// when `limit` bytes are read.
|
||||
func ReadAtMost(r io.Reader, limit int64) ([]byte, error) {
|
||||
limitedReader := &io.LimitedReader{R: r, N: limit}
|
||||
data, err := ioutil.ReadAll(limitedReader)
|
||||
if err != nil {
|
||||
return data, err
|
||||
}
|
||||
if limitedReader.N <= 0 {
|
||||
return data, ErrLimitReached
|
||||
}
|
||||
return data, nil
|
||||
}
|
Reference in New Issue
Block a user