]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Synchronize Torrent.Info
authorMatt Joiner <anacrolix@gmail.com>
Tue, 29 Aug 2017 05:16:53 +0000 (15:16 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 29 Aug 2017 05:16:53 +0000 (15:16 +1000)
client.go
reader.go
t.go
torrent.go

index 035af50d3107990b21c21563706745855ed49d1c..d81697b85423c2bd186c7f6177c7f1653ba3f346 100644 (file)
--- a/client.go
+++ b/client.go
@@ -141,8 +141,8 @@ func (cl *Client) WriteStatus(_w io.Writer) {
                        fmt.Fprint(w, t.name())
                }
                fmt.Fprint(w, "\n")
-               if t.Info() != nil {
-                       fmt.Fprintf(w, "%f%% of %d bytes (%s)", 100*(1-float64(t.bytesMissingLocked())/float64(t.Info().TotalLength())), t.length, humanize.Bytes(uint64(t.Info().TotalLength())))
+               if t.info != nil {
+                       fmt.Fprintf(w, "%f%% of %d bytes (%s)", 100*(1-float64(t.bytesMissingLocked())/float64(t.info.TotalLength())), t.length, humanize.Bytes(uint64(t.info.TotalLength())))
                } else {
                        w.WriteString("<missing metainfo>")
                }
index 7da3b48a11782d9b7dc2e2e1cc44a05af68c0365..5afab9aa95c116a1edb0924fd819737387a9c31f 100644 (file)
--- a/reader.go
+++ b/reader.go
@@ -195,9 +195,9 @@ func (r *Reader) readOnceAt(b []byte, pos int64, ctxErr *error) (n int, err erro
                        }
                }
                b1 := b[:avail]
-               pi := int(pos / r.t.Info().PieceLength)
-               ip := r.t.Info().Piece(pi)
-               po := pos % r.t.Info().PieceLength
+               pi := int(pos / r.t.info.PieceLength)
+               ip := r.t.info.Piece(pi)
+               po := pos % r.t.info.PieceLength
                missinggo.LimitLen(&b1, ip.Length()-po)
                n, err = r.t.readAt(b1, pos)
                if n != 0 {
diff --git a/t.go b/t.go
index abd9d354e3d110d640b89e6b2b1e31a6cef84dc1..13722d8a7421b911e8c063360e21ae54d3c0d16d 100644 (file)
--- a/t.go
+++ b/t.go
@@ -24,6 +24,8 @@ func (t *Torrent) GotInfo() <-chan struct{} {
 
 // Returns the metainfo info dictionary, or nil if it's not yet available.
 func (t *Torrent) Info() *metainfo.Info {
+       t.cl.mu.Lock()
+       defer t.cl.mu.Unlock()
        return t.info
 }
 
@@ -161,9 +163,7 @@ func (t *Torrent) CancelPieces(begin, end int) {
 // Returns handles to the files in the torrent. This requires the metainfo is
 // available first.
 func (t *Torrent) Files() (ret []File) {
-       t.cl.mu.Lock()
        info := t.Info()
-       t.cl.mu.Unlock()
        if info == nil {
                return
        }
index c2be1f0610649174410a52ef8e3c26c7ad435b5f..eb4f7a7da06b8e7d3fdb602533f01ff1085a4187 100644 (file)
@@ -442,7 +442,7 @@ func (t *Torrent) writeStatus(w io.Writer) {
                        return "?"
                }
        }())
-       if t.Info() != nil {
+       if t.info != nil {
                fmt.Fprintf(w, "Num Pieces: %d\n", t.numPieces())
                fmt.Fprint(w, "Piece States:")
                for _, psr := range t.pieceStateRuns() {