Skip to content

Commit

Permalink
fix: ethersphere#4808, remove fork & releoad node
Browse files Browse the repository at this point in the history
  • Loading branch information
asabya committed Jan 10, 2025
1 parent 44e3be2 commit 363365f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
18 changes: 17 additions & 1 deletion pkg/manifest/mantaray/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,26 @@ func (n *Node) Remove(ctx context.Context, path []byte, ls LoadSaver) error {
rest := path[len(f.prefix):]
if len(rest) == 0 {
// full path matched

// Make the ref all zeros to indicate that this node needs to re-uploaded
n.ref = zero32
// Set the refBytesSize to 32 so that unmarshall works properly
n.refBytesSize = len(n.ref)

// remove the fork
delete(n.forks, path[0])
return nil
}
return f.Node.Remove(ctx, rest, ls)
err := f.Node.Remove(ctx, rest, ls)
if err != nil {
return err
}
// Make the ref all zeros to indicate that this node needs to re-uploaded
n.ref = zero32
// Set the refBytesSize to 32 so that unmarshall works properly
n.refBytesSize = len(n.ref)

return nil
}

func common(a, b []byte) (c []byte) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/manifest/mantaray/persist.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
package mantaray

import (
"bytes"
"context"
"errors"

"golang.org/x/sync/errgroup"
)

Expand Down Expand Up @@ -61,7 +61,7 @@ func (n *Node) Save(ctx context.Context, s Saver) error {
}

func (n *Node) save(ctx context.Context, s Saver) error {
if n != nil && n.ref != nil {
if n != nil && n.ref != nil && !bytes.Equal(n.ref, zero32) {
return nil
}
select {
Expand Down
26 changes: 25 additions & 1 deletion pkg/manifest/mantaray/persist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,29 @@ func TestPersistRemove(t *testing.T) {
[]byte("img/2.png"),
},
},
{
name: "nested-prefix-is-not-collapsed",
toAdd: []mantaray.NodeEntry{
{
Path: []byte("index.html"),
},
{
Path: []byte("img/1.png"),
},
{
Path: []byte("img/2/test1.png"),
},
{
Path: []byte("img/2/test2.png"),
},
{
Path: []byte("robots.txt"),
},
},
toRemove: [][]byte{
[]byte("img/2/test1.png"),
},
},
} {
ctx := context.Background()
var ls mantaray.LoadSaver = newMockLoadSaver()
Expand Down Expand Up @@ -124,7 +147,6 @@ func TestPersistRemove(t *testing.T) {
}

ref := n.Reference()

// reload and remove
nn := mantaray.NewNodeRef(ref)
for i := 0; i < len(tc.toRemove); i++ {
Expand All @@ -134,10 +156,12 @@ func TestPersistRemove(t *testing.T) {
t.Fatalf("expected no error, got %v", err)
}
}

err = nn.Save(ctx, ls)
if err != nil {
t.Fatalf("expected no error, got %v", err)
}

ref = nn.Reference()

// reload and lookup removed node
Expand Down

0 comments on commit 363365f

Please sign in to comment.