From 144bbb6555ea0dbcfa02fe78b5cad0a657e42798 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 8 Aug 2018 10:21:14 -0700 Subject: [PATCH] add GetSize method to the v0v1 blockstore fixes hidden merge conflict License: MIT Signed-off-by: Steven Allen --- thirdparty/cidv0v1/blockstore.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/thirdparty/cidv0v1/blockstore.go b/thirdparty/cidv0v1/blockstore.go index 7b9faf521..df377239b 100644 --- a/thirdparty/cidv0v1/blockstore.go +++ b/thirdparty/cidv0v1/blockstore.go @@ -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 {