client.go | 24 ------------------------ cmd/torrent-pick/main.go | 13 +++---------- torrent.go | 8 -------- diff --git a/client.go b/client.go index e43c9f191d1e8219c6ad15bded6640f78a0f7031..f4e6bbb0346c3fa366d23e89b170dd6296494a41 100644 --- a/client.go +++ b/client.go @@ -2400,17 +2400,6 @@ } return true } -func (cl *Client) allNeededTorrentsCompleted() bool { - for _, t := range cl.torrents { - if !t.haveInfo() { - return false - } - if ! t.neededPiecesDownloaded() { - return false - } - } - return true -} // Returns true when all torrents are completely downloaded and false if the // client is stopped before that. @@ -2426,19 +2415,6 @@ } return true } -// Returns true when all requested chunks are completely downloaded and false if the -// client is stopped before that. -func (me *Client) WaitNeeded() bool { - me.mu.Lock() - defer me.mu.Unlock() - for !me.allNeededTorrentsCompleted() { - if me.stopped() { - return false - } - me.event.Wait() - } - return true -} func (me *Client) fillRequests(t *torrent, c *connection) { if c.Interested { diff --git a/cmd/torrent-pick/main.go b/cmd/torrent-pick/main.go index 88e3c32b61f1acefca8caab938cb8c0aa5670985..3b64152aba1a1f4a4f2e5827db0726ab21b3ac16 100644 --- a/cmd/torrent-pick/main.go +++ b/cmd/torrent-pick/main.go @@ -135,7 +135,7 @@ log.Fatal(err) } dstWriter := bufio.NewWriter(f) - + done := make(chan struct{}) for _, arg := range posArgs { t := func() torrent.Torrent { if strings.HasPrefix(arg, "magnet:") { @@ -171,21 +171,14 @@ log.Printf("Downloading file: %s", file.Path()) srcReader := io.NewSectionReader(t.NewReader(), file.Offset(), file.Length()) io.Copy(dstWriter, srcReader) + close(done) break } } }() } - done := make(chan struct{}) - go func() { - defer close(done) - if client.WaitNeeded() { - log.Print("downloaded ALL the torrents") - } else { - log.Fatal("y u no complete torrents?!") - } - }() + ticker := time.NewTicker(time.Second) waitDone: for { diff --git a/torrent.go b/torrent.go index d025185bc80a685fc5c34b620178e38f6ae4bdb5..74e49831b35866b11c5d282f22c36093823d22b7 100644 --- a/torrent.go +++ b/torrent.go @@ -515,14 +515,6 @@ func (t *torrent) numPieces() int { return t.Info.NumPieces() } -func (t *torrent) neededPiecesDownloaded() bool { - for i := range iter.N(t.Info.NumPieces()) { - if t.Pieces[i].Priority != piecePriorityNone && !t.pieceComplete(i) { - return false - } - } - return true -} func (t *torrent) numPiecesCompleted() (num int) { for i := range iter.N(t.Info.NumPieces()) {