]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Tidy up some storage close handling
authorMatt Joiner <anacrolix@gmail.com>
Sun, 11 Oct 2020 01:40:43 +0000 (12:40 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Sun, 11 Oct 2020 01:40:43 +0000 (12:40 +1100)
client_test.go
storage/piece_resource.go
test/transfer_test.go

index 777c596256116318ed957ff4de5e8633adfce2c5..dcb6d0be433cf1119f9e2978b48cebec312c67fe 100644 (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()
index 1ef0e602605339b7bd9dce63b6f25cb2acaac411..201d3f37fc382efe4e5c0d392d485837a65a59c5 100644 (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,
index 6cbc5f89c683d69f0b3710cb7d45b3bffe18f7cb..f549f913676fb38be29ac27b040334c5d5f0df6d 100644 (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) {