2016-06-20 07:51:05 +00:00
|
|
|
package storage
|
|
|
|
|
2016-07-06 03:38:16 +00:00
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/anacrolix/torrent/metainfo"
|
|
|
|
)
|
|
|
|
|
2017-03-30 10:38:44 +00:00
|
|
|
// Implementations track the completion of pieces. It must be concurrent-safe.
|
2017-05-22 02:15:48 +00:00
|
|
|
type PieceCompletion interface {
|
2016-08-26 10:29:05 +00:00
|
|
|
Get(metainfo.PieceKey) (bool, error)
|
|
|
|
Set(metainfo.PieceKey, bool) error
|
2016-10-25 08:07:26 +00:00
|
|
|
Close() error
|
2016-07-06 03:38:16 +00:00
|
|
|
}
|
2016-06-20 07:51:05 +00:00
|
|
|
|
2017-05-22 02:15:48 +00:00
|
|
|
func pieceCompletionForDir(dir string) (ret PieceCompletion) {
|
|
|
|
ret, err := NewBoltPieceCompletion(dir)
|
2016-06-20 07:51:05 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Printf("couldn't open piece completion db in %q: %s", dir, err)
|
2017-05-22 02:15:48 +00:00
|
|
|
ret = NewMapPieceCompletion()
|
2016-06-20 07:51:05 +00:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|