Fix Torrent.Drop to wait for storage close without client lock
This commit is contained in:
parent
d957502528
commit
7378d50a3c
|
@ -1258,15 +1258,13 @@ func useTorrentSource(ctx context.Context, source string, t *Torrent) (err error
|
||||||
return t.MergeSpec(TorrentSpecFromMetaInfo(&mi))
|
return t.MergeSpec(TorrentSpecFromMetaInfo(&mi))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cl *Client) dropTorrent(infoHash metainfo.Hash) (err error) {
|
func (cl *Client) dropTorrent(infoHash metainfo.Hash, wg *sync.WaitGroup) (err error) {
|
||||||
t, ok := cl.torrents[infoHash]
|
t, ok := cl.torrents[infoHash]
|
||||||
if !ok {
|
if !ok {
|
||||||
err = fmt.Errorf("no such torrent")
|
err = fmt.Errorf("no such torrent")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var wg sync.WaitGroup
|
err = t.close(wg)
|
||||||
defer wg.Wait()
|
|
||||||
err = t.close(&wg)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
5
t.go
5
t.go
|
@ -5,6 +5,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/anacrolix/missinggo/pubsub"
|
"github.com/anacrolix/missinggo/pubsub"
|
||||||
|
"github.com/anacrolix/sync"
|
||||||
|
|
||||||
"github.com/anacrolix/torrent/metainfo"
|
"github.com/anacrolix/torrent/metainfo"
|
||||||
)
|
)
|
||||||
|
@ -95,9 +96,11 @@ func (t *Torrent) PieceBytesMissing(piece int) int64 {
|
||||||
// this. No data corruption can, or should occur to either the torrent's data,
|
// this. No data corruption can, or should occur to either the torrent's data,
|
||||||
// or connected peers.
|
// or connected peers.
|
||||||
func (t *Torrent) Drop() {
|
func (t *Torrent) Drop() {
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
defer wg.Wait()
|
||||||
t.cl.lock()
|
t.cl.lock()
|
||||||
defer t.cl.unlock()
|
defer t.cl.unlock()
|
||||||
t.cl.dropTorrent(t.infoHash)
|
t.cl.dropTorrent(t.infoHash, &wg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Number of bytes of the entire torrent we have completed. This is the sum of
|
// Number of bytes of the entire torrent we have completed. This is the sum of
|
||||||
|
|
Loading…
Reference in New Issue