]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Remove FileStorePieces storage backend
authorMatt Joiner <anacrolix@gmail.com>
Thu, 5 Jan 2017 06:00:59 +0000 (17:00 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 5 Jan 2017 06:00:59 +0000 (17:00 +1100)
ResourcePIeces is now preferred.

client_test.go
storage/piece_file.go [deleted file]

index 716ea5078b608ae6d81fd569e9b9449a28d86bcb..b70e28975cd3b0d0f301dbeeb562f07e1dfd7523 100644 (file)
@@ -292,10 +292,6 @@ func fileCachePieceResourceStorage(fc *filecache.Cache) storage.ClientImpl {
        return storage.NewResourcePieces(fc.AsResourceProvider())
 }
 
-func fileCachePieceFileStorage(fc *filecache.Cache) storage.ClientImpl {
-       return storage.NewFileStorePieces(fc.AsFileStore())
-}
-
 func TestClientTransferSmallCache(t *testing.T) {
        testClientTransfer(t, testClientTransferParams{
                LeecherStorage: NewFileCacheClientStorageFactory(FileCacheClientStorageFactoryParams{
@@ -316,9 +312,6 @@ func TestClientTransferSmallCache(t *testing.T) {
 func TestClientTransferVarious(t *testing.T) {
        // Leecher storage
        for _, ls := range []storageFactory{
-               NewFileCacheClientStorageFactory(FileCacheClientStorageFactoryParams{
-                       Wrapper: fileCachePieceFileStorage,
-               }),
                NewFileCacheClientStorageFactory(FileCacheClientStorageFactoryParams{
                        Wrapper: fileCachePieceResourceStorage,
                }),
@@ -798,12 +791,10 @@ func testAddTorrentPriorPieceCompletion(t *testing.T, alreadyCompleted bool, csf
 }
 
 func TestAddTorrentPiecesAlreadyCompleted(t *testing.T) {
-       testAddTorrentPriorPieceCompletion(t, true, fileCachePieceFileStorage)
        testAddTorrentPriorPieceCompletion(t, true, fileCachePieceResourceStorage)
 }
 
 func TestAddTorrentPiecesNotAlreadyCompleted(t *testing.T) {
-       testAddTorrentPriorPieceCompletion(t, false, fileCachePieceFileStorage)
        testAddTorrentPriorPieceCompletion(t, false, fileCachePieceResourceStorage)
 }
 
@@ -852,7 +843,7 @@ func testDownloadCancel(t *testing.T, ps testDownloadCancelParams) {
        if ps.SetLeecherStorageCapacity {
                fc.SetCapacity(ps.LeecherStorageCapacity)
        }
-       cfg.DefaultStorage = storage.NewFileStorePieces(fc.AsFileStore())
+       cfg.DefaultStorage = storage.NewResourcePieces(fc.AsResourceProvider())
        cfg.DataDir = leecherDataDir
        leecher, _ := NewClient(&cfg)
        defer leecher.Close()
diff --git a/storage/piece_file.go b/storage/piece_file.go
deleted file mode 100644 (file)
index 2760751..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-package storage
-
-import (
-       "io"
-       "os"
-       "path"
-
-       "github.com/anacrolix/missinggo"
-
-       "github.com/anacrolix/torrent/metainfo"
-)
-
-type pieceFileStorage struct {
-       fs missinggo.FileStore
-}
-
-func NewFileStorePieces(fs missinggo.FileStore) ClientImpl {
-       return &pieceFileStorage{
-               fs: fs,
-       }
-}
-
-func (pieceFileStorage) Close() error { return nil }
-
-type pieceFileTorrentStorage struct {
-       s *pieceFileStorage
-}
-
-func (s *pieceFileStorage) OpenTorrent(info *metainfo.Info, infoHash metainfo.Hash) (TorrentImpl, error) {
-       return &pieceFileTorrentStorage{s}, nil
-}
-
-func (s *pieceFileTorrentStorage) Close() error {
-       return nil
-}
-
-func (s *pieceFileTorrentStorage) Piece(p metainfo.Piece) PieceImpl {
-       return pieceFileTorrentStoragePiece{s, p, s.s.fs}
-}
-
-type pieceFileTorrentStoragePiece struct {
-       ts *pieceFileTorrentStorage
-       p  metainfo.Piece
-       fs missinggo.FileStore
-}
-
-func (s pieceFileTorrentStoragePiece) completedPath() string {
-       return path.Join("completed", s.p.Hash().HexString())
-}
-
-func (s pieceFileTorrentStoragePiece) incompletePath() string {
-       return path.Join("incomplete", s.p.Hash().HexString())
-}
-
-func (s pieceFileTorrentStoragePiece) GetIsComplete() bool {
-       fi, err := s.fs.Stat(s.completedPath())
-       return err == nil && fi.Size() == s.p.Length()
-}
-
-func (s pieceFileTorrentStoragePiece) MarkComplete() error {
-       return s.fs.Rename(s.incompletePath(), s.completedPath())
-}
-
-func (s pieceFileTorrentStoragePiece) MarkNotComplete() error {
-       return s.fs.Remove(s.completedPath())
-}
-
-func (s pieceFileTorrentStoragePiece) openFile() (f missinggo.File, err error) {
-       f, err = s.fs.OpenFile(s.completedPath(), os.O_RDONLY)
-       if err == nil {
-               var fi os.FileInfo
-               fi, err = f.Stat()
-               if err == nil && fi.Size() == s.p.Length() {
-                       return
-               }
-               f.Close()
-       } else if !os.IsNotExist(err) {
-               return
-       }
-       f, err = s.fs.OpenFile(s.incompletePath(), os.O_RDONLY)
-       if os.IsNotExist(err) {
-               err = io.ErrUnexpectedEOF
-       }
-       return
-}
-
-func (s pieceFileTorrentStoragePiece) ReadAt(b []byte, off int64) (n int, err error) {
-       f, err := s.openFile()
-       if err != nil {
-               return
-       }
-       defer f.Close()
-       return f.ReadAt(b, off)
-}
-
-func (s pieceFileTorrentStoragePiece) WriteAt(b []byte, off int64) (n int, err error) {
-       f, err := s.fs.OpenFile(s.incompletePath(), os.O_WRONLY|os.O_CREATE)
-       if err != nil {
-               return
-       }
-       defer f.Close()
-       return f.WriteAt(b, off)
-}