From: Matt Joiner Date: Wed, 15 Apr 2020 03:07:17 +0000 (+1000) Subject: Clone the AnnounceList out of Torrent.Metainfo X-Git-Tag: v1.16.0~86 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=92162295af5a9f3e12a1303ffe6cc513d3a6e5ae;p=btrtrc.git Clone the AnnounceList out of Torrent.Metainfo Should fix a race with Torrent.AddTrackers --- diff --git a/metainfo/announcelist.go b/metainfo/announcelist.go index 3a5c09d4..b371f70d 100644 --- a/metainfo/announcelist.go +++ b/metainfo/announcelist.go @@ -2,6 +2,13 @@ package metainfo type AnnounceList [][]string +func (al AnnounceList) Clone() (ret AnnounceList) { + for _, tier := range al { + ret = append(ret, append([]string(nil), tier...)) + } + return +} + // Whether the AnnounceList should be preferred over a single URL announce. func (al AnnounceList) OverridesAnnounce(announce string) bool { for _, tier := range al { diff --git a/torrent.go b/torrent.go index db0126bf..d29c9a92 100644 --- a/torrent.go +++ b/torrent.go @@ -633,7 +633,7 @@ func (t *Torrent) newMetaInfo() metainfo.MetaInfo { CreationDate: time.Now().Unix(), Comment: "dynamic metainfo from client", CreatedBy: "go.torrent", - AnnounceList: t.metainfo.UpvertedAnnounceList(), + AnnounceList: t.metainfo.UpvertedAnnounceList().Clone(), InfoBytes: func() []byte { if t.haveInfo() { return t.metadataBytes