Handle data going missing
This commit is contained in:
parent
28455fb817
commit
a451bc7e6d
16
client.go
16
client.go
|
@ -280,8 +280,20 @@ func (cl *Client) torrentReadAt(t *torrent, off int64, p []byte) (n int, err err
|
|||
if len(p) == 0 {
|
||||
panic(len(p))
|
||||
}
|
||||
cl.prepareRead(t, off)
|
||||
return dataReadAt(t.data, p, off)
|
||||
// TODO: ReadAt should always try to fill the buffer.
|
||||
for {
|
||||
avail := cl.prepareRead(t, off)
|
||||
if avail < int64(len(p)) {
|
||||
p = p[:avail]
|
||||
}
|
||||
n, err = dataReadAt(t.data, p, off)
|
||||
if n != 0 || err != io.ErrUnexpectedEOF {
|
||||
break
|
||||
}
|
||||
// If we reach here, the data we thought was ready, isn't. So we
|
||||
// prepare it again, and retry.
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Sets priorities to download from the given offset. Returns when the piece
|
||||
|
|
|
@ -124,6 +124,10 @@ func (me *store) pieceRead(p metainfo.Piece) (f *os.File) {
|
|||
if !os.IsNotExist(err) {
|
||||
panic(err)
|
||||
}
|
||||
// Ermahgerd, self heal. This occurs when the underlying data goes
|
||||
// missing, likely due to a "cache flush", also known as deleting the
|
||||
// files. TODO: Trigger an asynchronous initCompleted.
|
||||
delete(me.completed, sliceToPieceHashArray(p.Hash()))
|
||||
f, err = os.Open(me.path(p, false))
|
||||
if err == nil {
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue