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)
34 // If it's allegedly complete, check that its constituent files have the necessary length.
35 for _, fi := range extentCompleteRequiredLengths(fs.p.Info, fs.p.Offset(), fs.p.Length()) {
36 s, err := os.Stat(fs.files[fi.fileIndex].path)
37 if err != nil || s.Size() < fi.length {
45 // The completion was wrong, fix it.
47 fs.completion.Set(fs.pieceKey(), false)
53 func (fs *filePieceImpl) MarkComplete() error {
54 return fs.completion.Set(fs.pieceKey(), true)
57 func (fs *filePieceImpl) MarkNotComplete() error {
58 return fs.completion.Set(fs.pieceKey(), false)