Skip to content

Commit

Permalink
fix expCid vs actualCid guard
Browse files Browse the repository at this point in the history
  • Loading branch information
i-norden authored and rvagg committed Apr 19, 2024
1 parent 17725cb commit e48f8c5
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down

0 comments on commit e48f8c5

Please sign in to comment.