Fix crash printing client status when a torrent info isn't available

This commit is contained in:
Matt Joiner 2014-06-29 18:56:19 +10:00
parent 434c954319
commit 5e7fe0383b
1 changed files with 7 additions and 1 deletions

View File

@ -118,7 +118,13 @@ func (cl *Client) WriteStatus(w io.Writer) {
cl.mu.Lock()
defer cl.mu.Unlock()
for _, t := range cl.torrents {
fmt.Fprintf(w, "%s: %f%%\n", t.Name(), 100*(1-float32(t.BytesLeft())/float32(t.Length())))
fmt.Fprintf(w, "%s: %f%%\n", t.Name(), func() float32 {
if !t.haveInfo() {
return 0
} else {
return 100 * (1 - float32(t.BytesLeft())/float32(t.Length()))
}
}())
t.WriteStatus(w)
}
}