diff --git a/blockstore.go b/blockstore.go index d634068..9fddc2d 100644 --- a/blockstore.go +++ b/blockstore.go @@ -152,8 +152,8 @@ func (b *Blockstore) GetSize(cid cid.Cid) (int, error) { func (b *Blockstore) Put(block blocks.Block) error { return b.env.Update(func(txn *lmdb.Txn) error { err := txn.Put(b.db, block.Cid().Hash(), block.RawData(), lmdb.NoOverwrite) - if err != nil && !lmdb.IsErrno(err, lmdb.KeyExist) { - return err + if err == nil || lmdb.IsErrno(err, lmdb.KeyExist) { + return nil } return err }) @@ -164,6 +164,7 @@ func (b *Blockstore) PutMany(blocks []blocks.Block) error { for _, block := range blocks { err := txn.Put(b.db, block.Cid().Hash(), block.RawData(), lmdb.NoOverwrite) if err != nil && !lmdb.IsErrno(err, lmdb.KeyExist) { + txn.Abort() // short-circuit return err } } diff --git a/go.mod b/go.mod index fdd320f..166eb50 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/multiformats/go-varint v0.0.6 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect github.com/pkg/errors v0.9.1 // indirect - github.com/raulk/go-bs-tests v0.0.3 + github.com/raulk/go-bs-tests v0.0.4 go.uber.org/zap v1.16.0 // indirect golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a // indirect golang.org/x/lint v0.0.0-20200130185559-910be7a94367 // indirect diff --git a/go.sum b/go.sum index 4102a90..bdeec56 100644 --- a/go.sum +++ b/go.sum @@ -92,8 +92,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/raulk/go-bs-tests v0.0.3 h1:Kg2BA12vA5oJ6BHb2BDinMkhcoL6IKME7dP/Ukvmb48= -github.com/raulk/go-bs-tests v0.0.3/go.mod h1:ZREaOSaReTvV4nY7Qh6Lkl+QisYXNBWcPRa0gjrIaG4= +github.com/raulk/go-bs-tests v0.0.4 h1:gYUYmIFMBnp2mtZQuiP/ZGtSTSPvmDBjWBz0xTZz4X8= +github.com/raulk/go-bs-tests v0.0.4/go.mod h1:ZREaOSaReTvV4nY7Qh6Lkl+QisYXNBWcPRa0gjrIaG4= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=