forked from TrueCloudLab/restic
Use int64 for the length in the RewindReader
This commit is contained in:
parent
99f7fd74e3
commit
929afc63d5
4 changed files with 21 additions and 21 deletions
|
@ -119,7 +119,7 @@ func (b *restBackend) Save(ctx context.Context, h restic.Handle, rd restic.Rewin
|
|||
if err != nil {
|
||||
return errors.Wrap(err, "NewRequest")
|
||||
}
|
||||
req.Header.Set("Content-Length", strconv.Itoa(rd.Length()))
|
||||
req.Header.Set("Content-Length", strconv.FormatInt(rd.Length(), 10))
|
||||
req.Header.Set("Content-Type", "application/octet-stream")
|
||||
req.Header.Set("Accept", contentTypeV2)
|
||||
|
||||
|
|
|
@ -443,7 +443,7 @@ func (s *Suite) TestListCancel(t *testing.T) {
|
|||
|
||||
type errorCloser struct {
|
||||
io.ReadSeeker
|
||||
l int
|
||||
l int64
|
||||
t testing.TB
|
||||
}
|
||||
|
||||
|
@ -452,7 +452,7 @@ func (ec errorCloser) Close() error {
|
|||
return errors.New("forbidden method close was called")
|
||||
}
|
||||
|
||||
func (ec errorCloser) Length() int {
|
||||
func (ec errorCloser) Length() int64 {
|
||||
return ec.l
|
||||
}
|
||||
|
||||
|
@ -536,7 +536,7 @@ func (s *Suite) TestSave(t *testing.T) {
|
|||
|
||||
// wrap the tempfile in an errorCloser, so we can detect if the backend
|
||||
// closes the reader
|
||||
err = b.Save(context.TODO(), h, errorCloser{t: t, l: length, ReadSeeker: tmpfile})
|
||||
err = b.Save(context.TODO(), h, errorCloser{t: t, l: int64(length), ReadSeeker: tmpfile})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -17,13 +17,13 @@ type RewindReader interface {
|
|||
|
||||
// Length returns the number of bytes that can be read from the Reader
|
||||
// after calling Rewind.
|
||||
Length() int
|
||||
Length() int64
|
||||
}
|
||||
|
||||
// ByteReader implements a RewindReader for a byte slice.
|
||||
type ByteReader struct {
|
||||
*bytes.Reader
|
||||
Len int
|
||||
Len int64
|
||||
}
|
||||
|
||||
// Rewind restarts the reader from the beginning of the data.
|
||||
|
@ -34,7 +34,7 @@ func (b *ByteReader) Rewind() error {
|
|||
|
||||
// Length returns the number of bytes read from the reader after Rewind is
|
||||
// called.
|
||||
func (b *ByteReader) Length() int {
|
||||
func (b *ByteReader) Length() int64 {
|
||||
return b.Len
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ var _ RewindReader = &ByteReader{}
|
|||
func NewByteReader(buf []byte) *ByteReader {
|
||||
return &ByteReader{
|
||||
Reader: bytes.NewReader(buf),
|
||||
Len: len(buf),
|
||||
Len: int64(len(buf)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ var _ RewindReader = &FileReader{}
|
|||
// FileReader implements a RewindReader for an open file.
|
||||
type FileReader struct {
|
||||
io.ReadSeeker
|
||||
Len int
|
||||
Len int64
|
||||
}
|
||||
|
||||
// Rewind seeks to the beginning of the file.
|
||||
|
@ -65,7 +65,7 @@ func (f *FileReader) Rewind() error {
|
|||
}
|
||||
|
||||
// Length returns the length of the file.
|
||||
func (f *FileReader) Length() int {
|
||||
func (f *FileReader) Length() int64 {
|
||||
return f.Len
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ func NewFileReader(f io.ReadSeeker) (*FileReader, error) {
|
|||
|
||||
fr := &FileReader{
|
||||
ReadSeeker: f,
|
||||
Len: int(pos),
|
||||
Len: pos,
|
||||
}
|
||||
|
||||
err = fr.Rewind()
|
||||
|
|
|
@ -57,15 +57,15 @@ func TestFileReader(t *testing.T) {
|
|||
}
|
||||
|
||||
func testRewindReader(t *testing.T, fn func() RewindReader, data []byte) {
|
||||
seed := time.Now().Unix()
|
||||
seed := time.Now().UnixNano()
|
||||
t.Logf("seed is %d", seed)
|
||||
rnd := rand.New(rand.NewSource(seed))
|
||||
|
||||
type ReaderTestFunc func(t testing.TB, r RewindReader, data []byte)
|
||||
var tests = []ReaderTestFunc{
|
||||
func(t testing.TB, rd RewindReader, data []byte) {
|
||||
if rd.Length() != len(data) {
|
||||
t.Fatalf("wrong length returned, want %d, got %d", len(data), rd.Length())
|
||||
if rd.Length() != int64(len(data)) {
|
||||
t.Fatalf("wrong length returned, want %d, got %d", int64(len(data)), rd.Length())
|
||||
}
|
||||
|
||||
buf := make([]byte, len(data))
|
||||
|
@ -78,8 +78,8 @@ func testRewindReader(t *testing.T, fn func() RewindReader, data []byte) {
|
|||
t.Fatalf("wrong data returned")
|
||||
}
|
||||
|
||||
if rd.Length() != len(data) {
|
||||
t.Fatalf("wrong length returned, want %d, got %d", len(data), rd.Length())
|
||||
if rd.Length() != int64(len(data)) {
|
||||
t.Fatalf("wrong length returned, want %d, got %d", int64(len(data)), rd.Length())
|
||||
}
|
||||
|
||||
err = rd.Rewind()
|
||||
|
@ -87,11 +87,11 @@ func testRewindReader(t *testing.T, fn func() RewindReader, data []byte) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if rd.Length() != len(data) {
|
||||
t.Fatalf("wrong length returned, want %d, got %d", len(data), rd.Length())
|
||||
if rd.Length() != int64(len(data)) {
|
||||
t.Fatalf("wrong length returned, want %d, got %d", int64(len(data)), rd.Length())
|
||||
}
|
||||
|
||||
buf2 := make([]byte, len(data))
|
||||
buf2 := make([]byte, int64(len(data)))
|
||||
_, err = io.ReadFull(rd, buf2)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -101,8 +101,8 @@ func testRewindReader(t *testing.T, fn func() RewindReader, data []byte) {
|
|||
t.Fatalf("wrong data returned")
|
||||
}
|
||||
|
||||
if rd.Length() != len(data) {
|
||||
t.Fatalf("wrong length returned, want %d, got %d", len(data), rd.Length())
|
||||
if rd.Length() != int64(len(data)) {
|
||||
t.Fatalf("wrong length returned, want %d, got %d", int64(len(data)), rd.Length())
|
||||
}
|
||||
},
|
||||
func(t testing.TB, rd RewindReader, data []byte) {
|
||||
|
|
Loading…
Reference in a new issue