From 1057ac80559d99eb88c639011a8f390da567893b Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Tue, 18 Nov 2014 14:34:13 -0600 Subject: [PATCH] Adding a duplicate magnet returns the existing torrent --- client.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index 3979b396..5c1223c4 100644 --- a/client.go +++ b/client.go @@ -1229,13 +1229,17 @@ func (cl *Client) AddMagnet(uri string) (t *torrent, err error) { if err != nil { return } + cl.mu.Lock() + defer cl.mu.Unlock() + t = cl.torrent(m.InfoHash) + if t != nil { + return + } t, err = newTorrent(m.InfoHash, [][]string{m.Trackers}, cl.halfOpenLimit) if err != nil { return } t.DisplayName = m.DisplayName - cl.mu.Lock() - defer cl.mu.Unlock() err = cl.addTorrent(t) if err != nil { t.Close()