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-10-12 05:09:32 +00:00
|
|
|
type PieceCompletionGetSetter interface {
|
|
|
|
Get(metainfo.PieceKey) (Completion, error)
|
|
|
|
Set(metainfo.PieceKey, bool) error
|
|
|
|
}
|
|
|
|
|
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 {
|
2017-10-12 05:09:32 +00:00
|
|
|
PieceCompletionGetSetter
|
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
|
|
|
|
}
|