8 "github.com/anacrolix/torrent/metainfo"
11 type filePieceImpl struct {
18 var _ PieceImpl = (*filePieceImpl)(nil)
20 func (me *filePieceImpl) pieceKey() metainfo.PieceKey {
21 return metainfo.PieceKey{me.infoHash, me.p.Index()}
24 func (fs *filePieceImpl) Completion() Completion {
25 c, err := fs.completion.Get(fs.pieceKey())
27 log.Printf("error getting piece completion: %s", err)
32 // If it's allegedly complete, check that its constituent files have the necessary length.
33 for _, fi := range extentCompleteRequiredLengths(fs.p.Info, fs.p.Offset(), fs.p.Length()) {
34 s, err := os.Stat(fs.files[fi.fileIndex].path)
35 if err != nil || s.Size() < fi.length {
42 // The completion was wrong, fix it.
43 fs.completion.Set(fs.pieceKey(), false)
48 func (fs *filePieceImpl) MarkComplete() error {
49 return fs.completion.Set(fs.pieceKey(), true)
52 func (fs *filePieceImpl) MarkNotComplete() error {
53 return fs.completion.Set(fs.pieceKey(), false)