]> Sergey Matveev's repositories - btrtrc.git/blobdiff - t.go
Use Option for cached Torrent length
[btrtrc.git] / t.go
diff --git a/t.go b/t.go
index 78c500dc438faf33b9d6f3a12dd669ff5fa5566c..a20e02c869f50453da296df548795d29ae909150 100644 (file)
--- a/t.go
+++ b/t.go
@@ -5,7 +5,7 @@ import (
        "strings"
 
        "github.com/anacrolix/chansync/events"
-       "github.com/anacrolix/missinggo/pubsub"
+       "github.com/anacrolix/missinggo/v2/pubsub"
        "github.com/anacrolix/sync"
 
        "github.com/anacrolix/torrent/metainfo"
@@ -32,7 +32,7 @@ func (t *Torrent) Info() (info *metainfo.Info) {
 // Returns a Reader bound to the torrent's data. All read calls block until the data requested is
 // actually available. Note that you probably want to ensure the Torrent Info is available first.
 func (t *Torrent) NewReader() Reader {
-       return t.newReader(0, *t.length)
+       return t.newReader(0, t.length())
 }
 
 func (t *Torrent) newReader(offset, length int64) Reader {
@@ -42,7 +42,7 @@ func (t *Torrent) newReader(offset, length int64) Reader {
                offset: offset,
                length: length,
        }
-       r.readaheadFunc = r.defaultReadaheadFunc
+       r.readaheadFunc = defaultReadaheadFunc
        t.addReader(&r)
        return &r
 }
@@ -115,7 +115,7 @@ func (t *Torrent) BytesCompleted() int64 {
 
 // The subscription emits as (int) the index of pieces as their state changes.
 // A state change is when the PieceState for a piece alters in value.
-func (t *Torrent) SubscribePieceStateChanges() *pubsub.Subscription {
+func (t *Torrent) SubscribePieceStateChanges() *pubsub.Subscription[PieceStateChange] {
        return t.pieceStateChanges.Subscribe()
 }
 
@@ -147,7 +147,7 @@ func (t *Torrent) Name() string {
 // The completed length of all the torrent data, in all its files. This is
 // derived from the torrent info, when it is available.
 func (t *Torrent) Length() int64 {
-       return *t.length
+       return t._length.Value()
 }
 
 // Returns a run-time generated metainfo for the torrent that includes the
@@ -190,7 +190,7 @@ func (t *Torrent) downloadPiecesLocked(begin, end pieceIndex) {
        }
 }
 
-func (t *Torrent) CancelPieces(begin, end pieceIndex, reason string) {
+func (t *Torrent) CancelPieces(begin, end pieceIndex) {
        t.cl.lock()
        t.cancelPiecesLocked(begin, end, "Torrent.CancelPieces")
        t.cl.unlock()
@@ -211,28 +211,17 @@ func (t *Torrent) initFiles() {
        var offset int64
        t.files = new([]*File)
        for _, fi := range t.info.UpvertedFiles() {
-               var path []string
-               if len(fi.PathUTF8) != 0 {
-                       path = fi.PathUTF8
-               } else {
-                       path = fi.Path
-               }
-               dp := t.info.Name
-               if len(fi.Path) != 0 {
-                       dp = strings.Join(fi.Path, "/")
-               }
                *t.files = append(*t.files, &File{
                        t,
-                       strings.Join(append([]string{t.info.Name}, path...), "/"),
+                       strings.Join(append([]string{t.info.BestName()}, fi.BestPath()...), "/"),
                        offset,
                        fi.Length,
                        fi,
-                       dp,
+                       fi.DisplayPath(t.info),
                        PiecePriorityNone,
                })
                offset += fi.Length
        }
-
 }
 
 // Returns handles to the files in the torrent. This requires that the Info is