Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/tree/ops/deletebranch.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ func DeleteBranch(ctx context.Context, e api.Entry, path *sdcpb.Path, owner stri
// if the relativePath is present, we need to naviagate
entry, err = NavigateSdcpbPath(ctx, e, path)
if err != nil {
if errors.Is(err, ErrNavigateSdcpbPathNotFound) {
return nil
}
return err
}
if entry == nil {
Expand Down
7 changes: 4 additions & 3 deletions pkg/tree/ops/navigatesdcpbpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ops

import (
"context"
"errors"
"fmt"

"github.com/sdcio/data-server/pkg/tree/api"
Expand All @@ -10,9 +11,9 @@ import (
sdcpb "github.com/sdcio/sdc-protos/sdcpb"
)

var (
ErrNavigateSdcpbPathNotFound = fmt.Errorf("path not found in tree")
)
// ErrNavigateSdcpbPathNotFound is returned (wrapped) when tree navigation cannot
// resolve a path segment. Delete-by-path callers (e.g. DeleteBranch) treat this as idempotent.
var ErrNavigateSdcpbPathNotFound = errors.New("path not found in tree")

func NavigateSdcpbPath(ctx context.Context, e api.Entry, path *sdcpb.Path) (api.Entry, error) {
if e == nil {
Expand Down
8 changes: 7 additions & 1 deletion pkg/tree/sharedEntryAttributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ func Test_sharedEntryAttributes_DeleteSubtree(t *testing.T) {
sharedEntryAttributes func(t *testing.T) api.Entry
args args
wantErr bool
// skipLeafCheck: path may not exist; idempotent DeleteBranch returns nil without deleting anything.
skipLeafCheck bool
}{
{
name: "one",
Expand Down Expand Up @@ -275,7 +277,8 @@ func Test_sharedEntryAttributes_DeleteSubtree(t *testing.T) {
},
owner: owner1,
},
wantErr: true,
wantErr: false,
skipLeafCheck: true,
},
}
for _, tt := range tests {
Expand All @@ -289,6 +292,9 @@ func Test_sharedEntryAttributes_DeleteSubtree(t *testing.T) {
if tt.wantErr {
return
}
if tt.skipLeafCheck {
return
}
e, err := ops.NavigateSdcpbPath(ctx, s, tt.args.relativePath)
if err != nil {
t.Error(err)
Expand Down
Loading