client.go | 4 ++-- reader.go | 6 +++--- t.go | 4 ++-- torrent.go | 2 +- diff --git a/client.go b/client.go index 035af50d3107990b21c21563706745855ed49d1c..d81697b85423c2bd186c7f6177c7f1653ba3f346 100644 --- a/client.go +++ b/client.go @@ -141,8 +141,8 @@ } else { 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("") } diff --git a/reader.go b/reader.go index 7da3b48a11782d9b7dc2e2e1cc44a05af68c0365..5afab9aa95c116a1edb0924fd819737387a9c31f 100644 --- a/reader.go +++ b/reader.go @@ -195,9 +195,9 @@ return } } 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 --- a/t.go +++ b/t.go @@ -24,6 +24,8 @@ } // 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 @@ // 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 } diff --git a/torrent.go b/torrent.go index c2be1f0610649174410a52ef8e3c26c7ad435b5f..eb4f7a7da06b8e7d3fdb602533f01ff1085a4187 100644 --- a/torrent.go +++ b/torrent.go @@ -442,7 +442,7 @@ } else { 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() {