Skip to content

Commit b31b0db

Browse files
committed
refactor: nil ref instead of all zeros
1 parent 92cbbd2 commit b31b0db

File tree

4 files changed

+8
-22
lines changed

4 files changed

+8
-22
lines changed

pkg/manifest/mantaray/marshal.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ func (n *Node) UnmarshalBinary(data []byte) error {
287287
bb.fromBytes(data[offset:])
288288
offset += 32 // skip forks
289289
return bb.iter(func(b byte) error {
290+
if refBytesSize == 0 {
291+
return nil
292+
}
290293
f := &fork{}
291294

292295
if len(data) < offset+nodeForkTypeBytesSize {
@@ -296,7 +299,6 @@ func (n *Node) UnmarshalBinary(data []byte) error {
296299
nodeType := data[offset]
297300

298301
nodeForkSize := nodeForkPreReferenceSize + refBytesSize
299-
300302
if nodeTypeIsWithMetadataType(nodeType) {
301303
if len(data) < offset+nodeForkPreReferenceSize+refBytesSize+nodeForkMetadataBytesSize {
302304
return fmt.Errorf("not enough bytes for node fork: %d (%d) on byte '%x': %w", (len(data) - offset), (nodeForkPreReferenceSize + refBytesSize + nodeForkMetadataBytesSize), []byte{b}, ErrInvalidManifest)

pkg/manifest/mantaray/node.go

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -311,28 +311,15 @@ func (n *Node) Remove(ctx context.Context, path []byte, ls LoadSaver) error {
311311
return ErrNotFound
312312
}
313313
rest := path[len(f.prefix):]
314+
defer func() {
315+
n.ref = nil
316+
}()
314317
if len(rest) == 0 {
315-
// full path matched
316-
317-
// Make the ref all zeros to indicate that this node needs to re-uploaded
318-
n.ref = zero32
319-
// Set the refBytesSize to 32 so that unmarshall works properly
320-
n.refBytesSize = len(n.ref)
321318

322-
// remove the fork
323319
delete(n.forks, path[0])
324320
return nil
325321
}
326-
err := f.Node.Remove(ctx, rest, ls)
327-
if err != nil {
328-
return err
329-
}
330-
// Make the ref all zeros to indicate that this node needs to re-uploaded
331-
n.ref = zero32
332-
// Set the refBytesSize to 32 so that unmarshall works properly
333-
n.refBytesSize = len(n.ref)
334-
335-
return nil
322+
return f.Node.Remove(ctx, rest, ls)
336323
}
337324

338325
func common(a, b []byte) (c []byte) {

pkg/manifest/mantaray/persist.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package mantaray
66

77
import (
8-
"bytes"
98
"context"
109
"errors"
1110
"golang.org/x/sync/errgroup"
@@ -61,7 +60,7 @@ func (n *Node) Save(ctx context.Context, s Saver) error {
6160
}
6261

6362
func (n *Node) save(ctx context.Context, s Saver) error {
64-
if n != nil && n.ref != nil && !bytes.Equal(n.ref, zero32) {
63+
if n != nil && n.ref != nil {
6564
return nil
6665
}
6766
select {

pkg/manifest/mantaray/persist_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ func TestPersistRemove(t *testing.T) {
145145
if err != nil {
146146
t.Fatalf("expected no error, got %v", err)
147147
}
148-
149148
ref := n.Reference()
150149
// reload and remove
151150
nn := mantaray.NewNodeRef(ref)
@@ -163,7 +162,6 @@ func TestPersistRemove(t *testing.T) {
163162
}
164163

165164
ref = nn.Reference()
166-
167165
// reload and lookup removed node
168166
nnn := mantaray.NewNodeRef(ref)
169167
for i := 0; i < len(tc.toRemove); i++ {

0 commit comments

Comments
 (0)