]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Torrent.MetaInfo: don't crash if info isn't available yet
authorMatt Joiner <anacrolix@gmail.com>
Mon, 23 May 2016 10:08:18 +0000 (20:08 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 23 May 2016 10:08:18 +0000 (20:08 +1000)
torrent.go

index 6cedebf37b7f9bb9bab07740140a5ba84c1f5850..6848a6fddf6ffc87468f6b5cf20b60301f74f434 100644 (file)
@@ -456,17 +456,17 @@ func (t *Torrent) announceList() (al [][]string) {
 
 // Returns a run-time generated MetaInfo that includes the info bytes and
 // announce-list as currently known to the client.
-func (t *Torrent) newMetaInfo() *metainfo.MetaInfo {
-       if t.metadataBytes == nil {
-               panic("info bytes not set")
-       }
-       return &metainfo.MetaInfo{
-               Info:         *t.info,
+func (t *Torrent) newMetaInfo() (mi *metainfo.MetaInfo) {
+       mi = &metainfo.MetaInfo{
                CreationDate: time.Now().Unix(),
                Comment:      "dynamic metainfo from client",
                CreatedBy:    "go.torrent",
                AnnounceList: t.announceList(),
        }
+       if t.info != nil {
+               mi.Info = *t.info
+       }
+       return
 }
 
 func (t *Torrent) bytesLeft() (left int64) {