From 7763b16329b2c9f161a99cf01deee3fcee886810 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Mon, 28 Apr 2025 10:42:00 +1000 Subject: [PATCH] Storage cap wasn't passed to piece resource implementation This breaks the tests, because it was actually masking bad behaviour. --- storage/piece-resource.go | 8 ++++++-- test/transfer_test.go | 10 +++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/storage/piece-resource.go b/storage/piece-resource.go index 9576fea5..404aec95 100644 --- a/storage/piece-resource.go +++ b/storage/piece-resource.go @@ -28,7 +28,7 @@ type ResourcePiecesOpts struct { // Sized puts require being able to stream from a statement executed on another connection. // Without them, we buffer the entire read and then put that. NoSizedPuts bool - Capacity *int64 + Capacity TorrentCapacity } func NewResourcePieces(p PieceProvider) ClientImpl { @@ -60,7 +60,11 @@ func (s piecePerResource) OpenTorrent( s, make([]sync.RWMutex, info.NumPieces()), } - return TorrentImpl{PieceWithHash: t.Piece, Close: t.Close}, nil + return TorrentImpl{ + PieceWithHash: t.Piece, + Close: t.Close, + Capacity: s.opts.Capacity, + }, nil } func (s piecePerResourceTorrentImpl) Piece(p metainfo.Piece, pieceHash g.Option[[]byte]) PieceImpl { diff --git a/test/transfer_test.go b/test/transfer_test.go index 501872fd..6d3e460b 100644 --- a/test/transfer_test.go +++ b/test/transfer_test.go @@ -31,11 +31,15 @@ func newFileCacheClientStorageFactory(ps fileCacheClientStorageFactoryParams) St if err != nil { panic(err) } - var sharedCapacity *int64 + var capFuncPtr storage.TorrentCapacity if ps.SetCapacity { - sharedCapacity = &ps.Capacity fc.SetCapacity(ps.Capacity) + f := func() (cap int64, capped bool) { + return ps.Capacity, ps.SetCapacity + } + capFuncPtr = &f } + return struct { storage.ClientImpl io.Closer @@ -43,7 +47,7 @@ func newFileCacheClientStorageFactory(ps fileCacheClientStorageFactoryParams) St storage.NewResourcePiecesOpts( fc.AsResourceProvider(), storage.ResourcePiecesOpts{ - Capacity: sharedCapacity, + Capacity: capFuncPtr, }), io.NopCloser(nil), } -- 2.48.1