From: Matt Joiner Date: Mon, 11 Aug 2025 01:19:13 +0000 (+1000) Subject: Don't panic on non-zero chunk sizes in Client.AddTorrentSpec X-Git-Tag: v1.59.0~2^2~31 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=5c778813ff6d2b9cbd9c847666ad492d76aeac28;p=btrtrc.git Don't panic on non-zero chunk sizes in Client.AddTorrentSpec --- diff --git a/client.go b/client.go index fd3466e2..76f986aa 100644 --- a/client.go +++ b/client.go @@ -1520,8 +1520,10 @@ type AddTorrentOpts struct { InfoHash infohash.T InfoHashV2 g.Option[infohash_v2.T] Storage storage.ClientImpl - ChunkSize pp.Integer - InfoBytes []byte + // Only applied for new torrents (check Client.AddTorrent* method bool return value). If 0, the + // default chunk size is used (16 KiB in current modern BitTorrent clients). + ChunkSize pp.Integer + InfoBytes []byte // Don't hash data if piece completion is missing. This is useful for very large torrents that // are dropped in place from an external source and trigger a lot of initial piece checks. DisableInitialPieceCheck bool @@ -1535,11 +1537,8 @@ type AddTorrentOpts struct { func (cl *Client) AddTorrentSpec(spec *TorrentSpec) (t *Torrent, new bool, err error) { t, new = cl.AddTorrentOpt(spec.AddTorrentOpts) modSpec := *spec - if new { - // ChunkSize was already applied by adding a new Torrent, and MergeSpec disallows changing - // it. - modSpec.ChunkSize = 0 - } + // ChunkSize was already applied by adding a new Torrent, and MergeSpec disallows changing it. + modSpec.ChunkSize = 0 err = t.MergeSpec(&modSpec) if err != nil && new { t.Drop()