diff --git a/pkg/manifest/mantaray/node.go b/pkg/manifest/mantaray/node.go index 9561c299db..437eeb460d 100644 --- a/pkg/manifest/mantaray/node.go +++ b/pkg/manifest/mantaray/node.go @@ -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) { diff --git a/pkg/manifest/mantaray/persist.go b/pkg/manifest/mantaray/persist.go index 9c08769a1d..2e872056e5 100644 --- a/pkg/manifest/mantaray/persist.go +++ b/pkg/manifest/mantaray/persist.go @@ -5,9 +5,9 @@ package mantaray import ( + "bytes" "context" "errors" - "golang.org/x/sync/errgroup" ) @@ -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 { diff --git a/pkg/manifest/mantaray/persist_test.go b/pkg/manifest/mantaray/persist_test.go index 1842b84e0e..345953c941 100644 --- a/pkg/manifest/mantaray/persist_test.go +++ b/pkg/manifest/mantaray/persist_test.go @@ -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() @@ -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++ { @@ -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