Only prune torrents if they have no peers

This commit is contained in:
Justin Li 2014-07-16 14:11:01 -04:00
parent 5f4f63cc44
commit e29fb21edb
3 changed files with 14 additions and 3 deletions

View file

@ -213,7 +213,7 @@ func (c *Conn) PurgeInactiveTorrents(before time.Time) error {
c.torrentsM.RLock()
for key, torrent := range c.torrents {
if torrent.LastAction < unixtime {
if torrent.LastAction < unixtime && torrent.PeerCount() == 0 {
queue = append(queue, key)
}
}

View file

@ -78,7 +78,15 @@ func TestTorrentPurging(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if status != http.StatusOK {
t.Fatalf("expected torrent to exist (got %s)", http.StatusText(status))
}
time.Sleep(1010 * time.Millisecond)
_, status, err = fetchPath(torrentApiPath)
if err != nil {
t.Fatal(err)
}
if status != http.StatusOK {
t.Fatalf("expected torrent to exist (got %s)", http.StatusText(status))
}
@ -88,13 +96,12 @@ func TestTorrentPurging(t *testing.T) {
peer["event"] = "stopped"
announce(peer, srv)
time.Sleep(1000 * time.Millisecond)
time.Sleep(1010 * time.Millisecond)
_, status, err = fetchPath(torrentApiPath)
if err != nil {
t.Fatal(err)
}
if status != http.StatusNotFound {
t.Fatalf("expected torrent to have been purged (got %s)", http.StatusText(status))
}

View file

@ -103,6 +103,10 @@ func (t *Torrent) InLeecherPool(p *Peer) (exists bool) {
return
}
func (t *Torrent) PeerCount() int {
return len(t.Seeders) + len(t.Leechers)
}
// User is a registered user for private trackers.
type User struct {
ID uint64 `json:"id"`