Skip to content

Commit 363365f

Browse files
committed
fix: #4808, remove fork & releoad node
1 parent 44e3be2 commit 363365f

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

pkg/manifest/mantaray/node.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,26 @@ func (n *Node) Remove(ctx context.Context, path []byte, ls LoadSaver) error {
313313
rest := path[len(f.prefix):]
314314
if len(rest) == 0 {
315315
// 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)
321+
322+
// remove the fork
316323
delete(n.forks, path[0])
317324
return nil
318325
}
319-
return f.Node.Remove(ctx, rest, ls)
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
320336
}
321337

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

pkg/manifest/mantaray/persist.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
package mantaray
66

77
import (
8+
"bytes"
89
"context"
910
"errors"
10-
1111
"golang.org/x/sync/errgroup"
1212
)
1313

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

6363
func (n *Node) save(ctx context.Context, s Saver) error {
64-
if n != nil && n.ref != nil {
64+
if n != nil && n.ref != nil && !bytes.Equal(n.ref, zero32) {
6565
return nil
6666
}
6767
select {

pkg/manifest/mantaray/persist_test.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,29 @@ func TestPersistRemove(t *testing.T) {
9797
[]byte("img/2.png"),
9898
},
9999
},
100+
{
101+
name: "nested-prefix-is-not-collapsed",
102+
toAdd: []mantaray.NodeEntry{
103+
{
104+
Path: []byte("index.html"),
105+
},
106+
{
107+
Path: []byte("img/1.png"),
108+
},
109+
{
110+
Path: []byte("img/2/test1.png"),
111+
},
112+
{
113+
Path: []byte("img/2/test2.png"),
114+
},
115+
{
116+
Path: []byte("robots.txt"),
117+
},
118+
},
119+
toRemove: [][]byte{
120+
[]byte("img/2/test1.png"),
121+
},
122+
},
100123
} {
101124
ctx := context.Background()
102125
var ls mantaray.LoadSaver = newMockLoadSaver()
@@ -124,7 +147,6 @@ func TestPersistRemove(t *testing.T) {
124147
}
125148

126149
ref := n.Reference()
127-
128150
// reload and remove
129151
nn := mantaray.NewNodeRef(ref)
130152
for i := 0; i < len(tc.toRemove); i++ {
@@ -134,10 +156,12 @@ func TestPersistRemove(t *testing.T) {
134156
t.Fatalf("expected no error, got %v", err)
135157
}
136158
}
159+
137160
err = nn.Save(ctx, ls)
138161
if err != nil {
139162
t.Fatalf("expected no error, got %v", err)
140163
}
164+
141165
ref = nn.Reference()
142166

143167
// reload and lookup removed node

0 commit comments

Comments
 (0)