]> Sergey Matveev's repositories - btrtrc.git/blobdiff - storage/sqlite/direct.go
Switch to github.com/go-llsqlite/adapter
[btrtrc.git] / storage / sqlite / direct.go
index 918bf7ef083363cd20f107f8b7f872fd36e611bf..8e0a4a8d4e435be70cf4d381b3b0b1966b27fef5 100644 (file)
@@ -6,7 +6,6 @@ package sqliteStorage
 import (
        "io"
 
-       "crawshaw.io/sqlite"
        "github.com/anacrolix/squirrel"
 
        "github.com/anacrolix/torrent/metainfo"
@@ -22,15 +21,23 @@ func NewDirectStorage(opts NewDirectStorageOpts) (_ storage.ClientImplCloser, er
        }
        return &client{
                cache,
-               cache.GetCapacity}, nil
+               cache.GetCapacity,
+       }, nil
+}
+
+func NewWrappingClient(cache *squirrel.Cache) storage.ClientImpl {
+       return &client{
+               cache,
+               cache.GetCapacity,
+       }
 }
 
 type client struct {
        *squirrel.Cache
-       capacity func() *int64
+       capacity func() (int64, bool)
 }
 
-func (c *client) OpenTorrent(info *metainfo.Info, infoHash metainfo.Hash) (storage.TorrentImpl, error) {
+func (c *client) OpenTorrent(*metainfo.Info, metainfo.Hash) (storage.TorrentImpl, error) {
        t := torrent{c.Cache}
        return storage.TorrentImpl{Piece: t.Piece, Close: t.Close, Capacity: &c.capacity}, nil
 }
@@ -41,11 +48,7 @@ type torrent struct {
 
 func (t torrent) Piece(p metainfo.Piece) storage.PieceImpl {
        ret := piece{
-               sb: squirrel.Blob{
-                       p.Hash().HexString(),
-                       p.Length(),
-                       t.c,
-               },
+               sb: t.c.OpenWithLength(p.Hash().HexString(), p.Length()),
        }
        ret.ReaderAt = &ret.sb
        ret.WriterAt = &ret.sb
@@ -71,12 +74,10 @@ func (p piece) MarkNotComplete() error {
 }
 
 func (p piece) Completion() (ret storage.Completion) {
-       err := p.sb.GetTag("verified", func(stmt *sqlite.Stmt) {
+       err := p.sb.GetTag("verified", func(stmt squirrel.SqliteStmt) {
                ret.Complete = stmt.ColumnInt(0) != 0
        })
        ret.Ok = err == nil
-       if err != nil {
-               panic(err)
-       }
+       ret.Err = err
        return
 }