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:
@ -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)
|
||||
|
Reference in New Issue
Block a user