Move storage.FileStore interface to missinggo
This commit is contained in:
parent
5856b91af0
commit
7790e72832
@ -315,7 +315,7 @@ func testClientTransfer(t *testing.T, ps testClientTransferParams) {
|
||||
if ps.SetLeecherStorageCapacity {
|
||||
fc.SetCapacity(ps.LeecherStorageCapacity)
|
||||
}
|
||||
cfg.DefaultStorage = storage.NewPieceFileStorage(storage.FileCacheFileStore{fc})
|
||||
cfg.DefaultStorage = storage.NewPieceFileStorage(fc.AsFileStore())
|
||||
leecher, err := NewClient(&cfg)
|
||||
require.NoError(t, err)
|
||||
defer leecher.Close()
|
||||
@ -730,7 +730,7 @@ func testAddTorrentPriorPieceCompletion(t *testing.T, alreadyCompleted bool) {
|
||||
require.NoError(t, err)
|
||||
greetingDataTempDir, greetingMetainfo := testutil.GreetingTestTorrent()
|
||||
defer os.RemoveAll(greetingDataTempDir)
|
||||
filePieceStore := storage.NewPieceFileStorage(storage.FileCacheFileStore{fileCache})
|
||||
filePieceStore := storage.NewPieceFileStorage(fileCache.AsFileStore())
|
||||
greetingData, err := filePieceStore.OpenTorrent(&greetingMetainfo.Info)
|
||||
require.NoError(t, err)
|
||||
writeTorrentData(greetingData, &greetingMetainfo.Info, []byte(testutil.GreetingFileContents))
|
||||
@ -821,7 +821,7 @@ func testDownloadCancel(t *testing.T, ps testDownloadCancelParams) {
|
||||
if ps.SetLeecherStorageCapacity {
|
||||
fc.SetCapacity(ps.LeecherStorageCapacity)
|
||||
}
|
||||
cfg.DefaultStorage = storage.NewPieceFileStorage(storage.FileCacheFileStore{fc})
|
||||
cfg.DefaultStorage = storage.NewPieceFileStorage(fc.AsFileStore())
|
||||
cfg.DataDir = leecherDataDir
|
||||
leecher, _ := NewClient(&cfg)
|
||||
defer leecher.Close()
|
||||
|
@ -6,40 +6,15 @@ import (
|
||||
"path"
|
||||
|
||||
"github.com/anacrolix/missinggo"
|
||||
"github.com/anacrolix/missinggo/filecache"
|
||||
|
||||
"github.com/anacrolix/torrent/metainfo"
|
||||
)
|
||||
|
||||
type FileStore interface {
|
||||
OpenFile(path string, flags int) (File, error)
|
||||
Stat(path string) (os.FileInfo, error)
|
||||
Rename(from, to string) error
|
||||
Remove(path string) error
|
||||
}
|
||||
|
||||
type File interface {
|
||||
io.ReaderAt
|
||||
io.WriterAt
|
||||
io.Writer
|
||||
io.Reader
|
||||
io.Closer
|
||||
io.Seeker
|
||||
}
|
||||
|
||||
type FileCacheFileStore struct {
|
||||
*filecache.Cache
|
||||
}
|
||||
|
||||
func (me FileCacheFileStore) OpenFile(p string, f int) (File, error) {
|
||||
return me.Cache.OpenFile(p, f)
|
||||
}
|
||||
|
||||
type pieceFileStorage struct {
|
||||
fs FileStore
|
||||
fs missinggo.FileStore
|
||||
}
|
||||
|
||||
func NewPieceFileStorage(fs FileStore) I {
|
||||
func NewPieceFileStorage(fs missinggo.FileStore) I {
|
||||
return &pieceFileStorage{
|
||||
fs: fs,
|
||||
}
|
||||
@ -64,7 +39,7 @@ func (me *pieceFileTorrentStorage) Piece(p metainfo.Piece) Piece {
|
||||
type pieceFileTorrentStoragePiece struct {
|
||||
ts *pieceFileTorrentStorage
|
||||
p metainfo.Piece
|
||||
fs FileStore
|
||||
fs missinggo.FileStore
|
||||
}
|
||||
|
||||
func (me pieceFileTorrentStoragePiece) completedPath() string {
|
||||
|
Loading…
x
Reference in New Issue
Block a user