2016-06-20 15:51:05 +08:00
|
|
|
package storage
|
|
|
|
|
2016-07-06 11:38:16 +08:00
|
|
|
import (
|
2020-05-02 16:37:04 +08:00
|
|
|
"github.com/anacrolix/log"
|
2016-07-06 11:38:16 +08:00
|
|
|
|
|
|
|
"github.com/anacrolix/torrent/metainfo"
|
|
|
|
)
|
|
|
|
|
2017-10-12 13:09:32 +08:00
|
|
|
type PieceCompletionGetSetter interface {
|
|
|
|
Get(metainfo.PieceKey) (Completion, error)
|
2018-01-11 19:10:52 +08:00
|
|
|
Set(_ metainfo.PieceKey, complete bool) error
|
2017-10-12 13:09:32 +08:00
|
|
|
}
|
|
|
|
|
2017-03-30 18:38:44 +08:00
|
|
|
// Implementations track the completion of pieces. It must be concurrent-safe.
|
2017-05-22 10:15:48 +08:00
|
|
|
type PieceCompletion interface {
|
2017-10-12 13:09:32 +08:00
|
|
|
PieceCompletionGetSetter
|
2016-10-25 16:07:26 +08:00
|
|
|
Close() error
|
2016-07-06 11:38:16 +08:00
|
|
|
}
|
2016-06-20 15:51:05 +08:00
|
|
|
|
2023-04-27 15:58:22 +08:00
|
|
|
// use sqlite by default
|
|
|
|
// if sqlite connection fails, use a map
|
2017-05-22 10:15:48 +08:00
|
|
|
func pieceCompletionForDir(dir string) (ret PieceCompletion) {
|
2021-05-14 13:51:26 +08:00
|
|
|
ret, err := NewDefaultPieceCompletionForDir(dir)
|
2016-06-20 15:51:05 +08:00
|
|
|
if err != nil {
|
|
|
|
log.Printf("couldn't open piece completion db in %q: %s", dir, err)
|
2017-05-22 10:15:48 +08:00
|
|
|
ret = NewMapPieceCompletion()
|
2016-06-20 15:51:05 +08:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|