From: Matt Joiner Date: Sun, 29 Jun 2014 08:56:19 +0000 (+1000) Subject: Fix crash printing client status when a torrent info isn't available X-Git-Tag: v1.0.0~1699 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=5e7fe0383b2bb26af9e3a2eedfcf0af028545768;p=btrtrc.git Fix crash printing client status when a torrent info isn't available --- diff --git a/client.go b/client.go index 2e60d9b6..ad1afff6 100644 --- a/client.go +++ b/client.go @@ -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) } }