From e48f8c5f13e2c6cbd6d033de40db9a197b1af7d9 Mon Sep 17 00:00:00 2001 From: i-norden Date: Mon, 16 Oct 2023 15:00:09 -0500 Subject: [PATCH] fix expCid vs actualCid guard --- store.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/store.go b/store.go index 8210cf3..a5bdd0f 100644 --- a/store.go +++ b/store.go @@ -103,7 +103,7 @@ func (s *BasicIpldStore) Put(ctx context.Context, v interface{}) (cid.Cid, error var expCid cid.Cid if c, ok := v.(cidProvider); ok { - expCid := c.Cid() + expCid = c.Cid() pref := expCid.Prefix() mhType = pref.MhType mhLen = pref.MhLength @@ -133,15 +133,15 @@ func (s *BasicIpldStore) Put(ctx context.Context, v interface{}) (cid.Cid, error return cid.Undef, err } - if err := s.Blocks.Put(ctx, blk); err != nil { - return cid.Undef, err - } - blkCid := blk.Cid() if expCid != cid.Undef && blkCid != expCid { return cid.Undef, fmt.Errorf("your object is not being serialized the way it expects to") } + if err := s.Blocks.Put(ctx, blk); err != nil { + return cid.Undef, err + } + return blkCid, nil } @@ -150,15 +150,15 @@ func (s *BasicIpldStore) Put(ctx context.Context, v interface{}) (cid.Cid, error return cid.Undef, err } - if err := s.Blocks.Put(ctx, nd); err != nil { - return cid.Undef, err - } - ndCid := nd.Cid() if expCid != cid.Undef && ndCid != expCid { return cid.Undef, fmt.Errorf("your object is not being serialized the way it expects to") } + if err := s.Blocks.Put(ctx, nd); err != nil { + return cid.Undef, err + } + return ndCid, nil }