2
0
mirror of synced 2025-02-23 22:28:11 +00:00

Remove FileStorePieces storage backend

ResourcePIeces is now preferred.
This commit is contained in:
Matt Joiner 2017-01-05 17:00:59 +11:00
parent 1e033d5f91
commit 1c37903a74
2 changed files with 1 additions and 113 deletions

View 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()

View File

@ -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)
}