Fixes #381.
import (
"encoding/binary"
+ "io"
"github.com/anacrolix/missinggo/x"
bolt "github.com/etcd-io/bbolt"
err = me.db.View(func(tx *bolt.Tx) error {
db := tx.Bucket(dataBucketKey)
if db == nil {
- return nil
+ return io.EOF
}
ci := off / chunkSize
off %= chunkSize
for len(b) != 0 {
ck := me.chunkKey(int(ci))
_b := db.Get(ck[:])
+ // If the chunk is the wrong size, assume it's missing as we can't rely on the data.
if len(_b) != chunkSize {
- break
+ return io.EOF
}
n1 := copy(b, _b[off:])
off = 0
continue
}
err = err1
- if err == io.EOF {
- // Lies.
- err = io.ErrUnexpectedEOF
- }
return
}
off -= fi.Length
p := info.Piece(0)
n, err := io.Copy(&buf, io.NewSectionReader(ts.Piece(p), 0, p.Length()))
assert.EqualValues(t, 1, n)
- assert.Equal(t, io.ErrUnexpectedEOF, err)
+ switch err {
+ case nil, io.EOF:
+ default:
+ t.Errorf("expected nil or EOF error from truncated piece, got %v", err)
+ }
}
if n > len(b) {
panic(n)
}
- off += int64(n)
- if err == io.EOF && off < p.mip.Length() {
- err = io.ErrUnexpectedEOF
- }
- if err == nil && off >= p.mip.Length() {
- err = io.EOF
- }
if n == 0 && err == nil {
- err = io.ErrUnexpectedEOF
+ panic("io.Copy will get stuck")
}
+ off += int64(n)
if off < p.mip.Length() && err != nil {
p.MarkNotComplete()
}
cfg.DownloadRateLimiter = ps.LeecherDownloadRateLimiter
}
cfg.Seed = false
- //cfg.Debug = true
if ps.ConfigureLeecher.Config != nil {
ps.ConfigureLeecher.Config(cfg)
}
p := t.piece(index)
sum, copyErr := t.hashPiece(index)
correct := sum == *p.hash
- if !correct {
+ switch copyErr {
+ case nil, io.EOF:
+ default:
log.Fmsg("piece %v (%s) hash failure copy error: %v", p, p.hash.HexString(), copyErr).Log(t.logger)
}
t.storageLock.RUnlock()