Tidy up some storage close handling

This commit is contained in:
Matt Joiner 2020-10-11 12:40:43 +11:00
parent 3d7a95a65d
commit 898260c177
3 changed files with 18 additions and 9 deletions

View File

@ -151,7 +151,7 @@ func TestAddDropManyTorrents(t *testing.T) {
}
}
func fileCachePieceResourceStorage(fc *filecache.Cache) storage.ClientImplCloser {
func fileCachePieceResourceStorage(fc *filecache.Cache) storage.ClientImpl {
return storage.NewResourcePieces(fc.AsResourceProvider())
}
@ -367,7 +367,7 @@ func writeTorrentData(ts *storage.Torrent, info metainfo.Info, b []byte) {
}
}
func testAddTorrentPriorPieceCompletion(t *testing.T, alreadyCompleted bool, csf func(*filecache.Cache) storage.ClientImplCloser) {
func testAddTorrentPriorPieceCompletion(t *testing.T, alreadyCompleted bool, csf func(*filecache.Cache) storage.ClientImpl) {
fileCacheDir, err := ioutil.TempDir("", "")
require.NoError(t, err)
defer os.RemoveAll(fileCacheDir)
@ -376,7 +376,6 @@ func testAddTorrentPriorPieceCompletion(t *testing.T, alreadyCompleted bool, csf
greetingDataTempDir, greetingMetainfo := testutil.GreetingTestTorrent()
defer os.RemoveAll(greetingDataTempDir)
filePieceStore := csf(fileCache)
defer filePieceStore.Close()
info, err := greetingMetainfo.UnmarshalInfo()
require.NoError(t, err)
ih := greetingMetainfo.HashInfoBytes()

View File

@ -16,21 +16,25 @@ type piecePerResource struct {
p resource.Provider
}
func NewResourcePieces(p resource.Provider) ClientImplCloser {
func NewResourcePieces(p resource.Provider) ClientImpl {
return &piecePerResource{
p: p,
}
}
func (s *piecePerResource) OpenTorrent(info *metainfo.Info, infoHash metainfo.Hash) (TorrentImpl, error) {
return s, nil
type piecePerResourceTorrentImpl struct {
piecePerResource
}
func (s *piecePerResource) Close() error {
func (piecePerResourceTorrentImpl) Close() error {
return nil
}
func (s *piecePerResource) Piece(p metainfo.Piece) PieceImpl {
func (s piecePerResource) OpenTorrent(info *metainfo.Info, infoHash metainfo.Hash) (TorrentImpl, error) {
return piecePerResourceTorrentImpl{s}, nil
}
func (s piecePerResource) Piece(p metainfo.Piece) PieceImpl {
return piecePerResourcePiece{
mp: p,
rp: s.p,

View File

@ -221,7 +221,13 @@ func TestClientTransferRateLimitedDownload(t *testing.T) {
}
func fileCachePieceResourceStorage(fc *filecache.Cache) storage.ClientImplCloser {
return storage.NewResourcePieces(fc.AsResourceProvider())
return struct {
storage.ClientImpl
io.Closer
}{
storage.NewResourcePieces(fc.AsResourceProvider()),
ioutil.NopCloser(nil),
}
}
func testClientTransferSmallCache(t *testing.T, setReadahead bool, readahead int64) {