]> Sergey Matveev's repositories - btrtrc.git/blobdiff - storage/file_storage_piece.go
Remove the InfoEx type, and don't generate its infohash on the fly
[btrtrc.git] / storage / file_storage_piece.go
index 44648c136e89a387f5c30156930449058fc556f1..915d5d0d1b637c76eec8956b880f2448ed70fdbd 100644 (file)
@@ -14,14 +14,18 @@ type fileStoragePiece struct {
        r io.ReaderAt
 }
 
+func (me *fileStoragePiece) pieceKey() metainfo.PieceKey {
+       return metainfo.PieceKey{me.infoHash, me.p.Index()}
+}
+
 func (fs *fileStoragePiece) GetIsComplete() bool {
-       ret, err := fs.completion.Get(fs.p)
+       ret, err := fs.completion.Get(fs.pieceKey())
        if err != nil || !ret {
                return false
        }
        // If it's allegedly complete, check that its constituent files have the
        // necessary length.
-       for _, fi := range extentCompleteRequiredLengths(&fs.p.Info.Info, fs.p.Offset(), fs.p.Length()) {
+       for _, fi := range extentCompleteRequiredLengths(fs.p.Info, fs.p.Offset(), fs.p.Length()) {
                s, err := os.Stat(fs.fileInfoName(fi))
                if err != nil || s.Size() < fi.Length {
                        ret = false
@@ -32,12 +36,12 @@ func (fs *fileStoragePiece) GetIsComplete() bool {
                return true
        }
        // The completion was wrong, fix it.
-       fs.completion.Set(fs.p, false)
+       fs.completion.Set(fs.pieceKey(), false)
        return false
 }
 
 func (fs *fileStoragePiece) MarkComplete() error {
-       fs.completion.Set(fs.p, true)
+       fs.completion.Set(fs.pieceKey(), true)
        return nil
 }
 
@@ -50,6 +54,6 @@ func (fsp *fileStoragePiece) ReadAt(b []byte, off int64) (n int, err error) {
        if off < 0 || off >= fsp.p.Length() {
                return
        }
-       fsp.completion.Set(fsp.p, false)
+       fsp.completion.Set(fsp.pieceKey(), false)
        return
 }