client.go | 2 +- torrent.go | 8 +++++++- diff --git a/client.go b/client.go index 5e635f27c6a8ecb9267444a8c601bdb436c1e6f6..66abeb847240438dabd4759eb95a50d0255590fa 100644 --- a/client.go +++ b/client.go @@ -1508,7 +1508,7 @@ t.addTrackers(spec.Trackers) t.maybeNewConns() t.dataDownloadDisallowed.SetBool(spec.DisallowDataDownload) t.dataUploadDisallowed = spec.DisallowDataUpload - return errors.Join(t.AddPieceLayers(spec.PieceLayers)...) + return errors.Join(t.addPieceLayersLocked(spec.PieceLayers)...) } func (cl *Client) dropTorrent(t *Torrent, wg *sync.WaitGroup) (err error) { diff --git a/torrent.go b/torrent.go index d1f4a646838f0b4c480ca38913720432d0d8cac5..39bffd77d101d8966d9f7edcbe4cf484fc47240d 100644 --- a/torrent.go +++ b/torrent.go @@ -425,7 +425,7 @@ } } } -func (t *Torrent) AddPieceLayers(layers map[string]string) (errs []error) { +func (t *Torrent) addPieceLayersLocked(layers map[string]string) (errs []error) { if layers == nil { return } @@ -474,6 +474,12 @@ p.setV2Hash(hashes[i]) } } return +} + +func (t *Torrent) AddPieceLayers(layers map[string]string) (errs []error) { + t.cl.lock() + defer t.cl.unlock() + return t.addPieceLayersLocked(layers) } // Returns the index of the first file containing the piece. files must be