1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-05-17 23:16:11 +08:00

add GetSize method to the v0v1 blockstore

fixes hidden merge conflict

License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
This commit is contained in:
Steven Allen
2018-08-08 10:21:14 -07:00
parent 92099a2ed1
commit 144bbb6555

View File

@ -2,9 +2,9 @@ package cidv0v1
import (
mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
bs "gx/ipfs/QmTCHqj6s51pDu1GaPGyBW2VdmCUvtzLCF6nWykfX9ZYRt/go-ipfs-blockstore"
blocks "gx/ipfs/QmVzK524a2VWLqyvtBeiHKsUAWYgeAk4DBeZoY7vpNPNRx/go-block-format"
cid "gx/ipfs/QmYVNvtQkeZ6AKSwDrjQTs432QtL6umrrK41EBq3cu7iSP/go-cid"
bs "gx/ipfs/QmadMhXJLHMFjpRmh85XjpmVDkEtQpNYEZNRpWRvYVLrvb/go-ipfs-blockstore"
)
type blockstore struct {
@ -57,6 +57,21 @@ func (b *blockstore) Get(c *cid.Cid) (blocks.Block, error) {
return block, nil
}
func (b *blockstore) GetSize(c *cid.Cid) (int, error) {
size, err := b.Blockstore.GetSize(c)
if err == nil {
return size, nil
}
if err != bs.ErrNotFound {
return -1, err
}
c1 := tryOtherCidVersion(c)
if c1 == nil {
return -1, bs.ErrNotFound
}
return b.Blockstore.GetSize(c1)
}
func tryOtherCidVersion(c *cid.Cid) *cid.Cid {
prefix := c.Prefix()
if prefix.Codec != cid.DagProtobuf || prefix.MhType != mh.SHA2_256 || prefix.MhLength != 32 {