Skip to content

Commit e48f8c5

Browse files
i-nordenrvagg
authored andcommitted
fix expCid vs actualCid guard
1 parent 17725cb commit e48f8c5

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

store.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (s *BasicIpldStore) Put(ctx context.Context, v interface{}) (cid.Cid, error
103103

104104
var expCid cid.Cid
105105
if c, ok := v.(cidProvider); ok {
106-
expCid := c.Cid()
106+
expCid = c.Cid()
107107
pref := expCid.Prefix()
108108
mhType = pref.MhType
109109
mhLen = pref.MhLength
@@ -133,15 +133,15 @@ func (s *BasicIpldStore) Put(ctx context.Context, v interface{}) (cid.Cid, error
133133
return cid.Undef, err
134134
}
135135

136-
if err := s.Blocks.Put(ctx, blk); err != nil {
137-
return cid.Undef, err
138-
}
139-
140136
blkCid := blk.Cid()
141137
if expCid != cid.Undef && blkCid != expCid {
142138
return cid.Undef, fmt.Errorf("your object is not being serialized the way it expects to")
143139
}
144140

141+
if err := s.Blocks.Put(ctx, blk); err != nil {
142+
return cid.Undef, err
143+
}
144+
145145
return blkCid, nil
146146
}
147147

@@ -150,15 +150,15 @@ func (s *BasicIpldStore) Put(ctx context.Context, v interface{}) (cid.Cid, error
150150
return cid.Undef, err
151151
}
152152

153-
if err := s.Blocks.Put(ctx, nd); err != nil {
154-
return cid.Undef, err
155-
}
156-
157153
ndCid := nd.Cid()
158154
if expCid != cid.Undef && ndCid != expCid {
159155
return cid.Undef, fmt.Errorf("your object is not being serialized the way it expects to")
160156
}
161157

158+
if err := s.Blocks.Put(ctx, nd); err != nil {
159+
return cid.Undef, err
160+
}
161+
162162
return ndCid, nil
163163
}
164164

0 commit comments

Comments
 (0)