1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-09 19:32:24 +08:00

blocks: Don't re-Put blocks we already have

Commit 1192be196b3d0acca2e2dce5ffd5d12a924fdc5a tried to do this, but
had a simple mistake. Functions returning `bool, error` pretty much
never return `true, anError`, so that branch was never taken.

Also fix the partial sentence in the
This commit is contained in:
Tommi Virtanen
2015-04-28 16:05:52 -07:00
parent 1b51d9dbf5
commit a743290316

View File

@ -64,10 +64,11 @@ func (bs *blockstore) Get(k u.Key) (*blocks.Block, error) {
}
func (bs *blockstore) Put(block *blocks.Block) error {
// Has is cheaper than
k := block.Key().DsKey()
// Has is cheaper than Put, so see if we already have it
exists, err := bs.datastore.Has(k)
if err != nil && exists {
if err == nil && exists {
return nil // already stored.
}
return bs.datastore.Put(k, block.Data)