Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix propfinds for spaces #2254

Merged
merged 1 commit into from
Nov 16, 2021
Merged
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
5 changes: 5 additions & 0 deletions changelog/unreleased/fix-spaces-propfind.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Fix spaces propfind

Fixed the deep listing of spaces.

https://github.com/cs3org/reva/pull/2254
46 changes: 33 additions & 13 deletions internal/http/services/owncloud/ocdav/propfind.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"net/http"
"net/url"
"path"
"path/filepath"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -122,11 +123,15 @@ func (s *svc) handleSpacesPropfind(w http.ResponseWriter, r *http.Request, space
}

// parentInfo Path is the name but we need /
parentInfo.Path = "/"
if r.URL.Path != "" {
parentInfo.Path = r.URL.Path
} else {
parentInfo.Path = "/"
}

// prefix space id to paths
for i := range resourceInfos {
resourceInfos[i].Path = path.Join("/", spaceID, r.URL.Path, resourceInfos[i].Path)
resourceInfos[i].Path = path.Join("/", spaceID, resourceInfos[i].Path)
}

s.propfindResponse(ctx, w, r, "", pf, parentInfo, resourceInfos, sublog)
Expand Down Expand Up @@ -221,6 +226,10 @@ func (s *svc) getResourceInfos(ctx context.Context, w http.ResponseWriter, r *ht
return nil, nil, false
}

if spacesPropfind {
res.Info.Path = ref.Path
}

parentInfo := res.Info
resourceInfos := []*provider.ResourceInfo{parentInfo}

Expand Down Expand Up @@ -279,9 +288,18 @@ func (s *svc) getResourceInfos(ctx context.Context, w http.ResponseWriter, r *ht
for len(stack) > 0 {
// retrieve path on top of stack
path := stack[len(stack)-1]
ref = &provider.Reference{Path: path}

var nRef *provider.Reference
if spacesPropfind {
nRef = &provider.Reference{
ResourceId: ref.ResourceId,
Path: path,
}
} else {
nRef = &provider.Reference{Path: path}
}
req := &provider.ListContainerRequest{
Ref: ref,
Ref: nRef,
ArbitraryMetadataKeys: metadataKeys,
}
res, err := client.ListContainer(ctx, req)
Expand All @@ -295,24 +313,26 @@ func (s *svc) getResourceInfos(ctx context.Context, w http.ResponseWriter, r *ht
return nil, nil, false
}

resourceInfos = append(resourceInfos, res.Infos...)

if depth != "infinity" {
break
}

// TODO: stream response to avoid storing too many results in memory

stack = stack[:len(stack)-1]

// check sub-containers in reverse order and add them to the stack
// the reversed order here will produce a more logical sorting of results
for i := len(res.Infos) - 1; i >= 0; i-- {
// for i := range res.Infos {
if spacesPropfind {
res.Infos[i].Path = utils.MakeRelativePath(filepath.Join(nRef.Path, res.Infos[i].Path))
}
if res.Infos[i].Type == provider.ResourceType_RESOURCE_TYPE_CONTAINER {
stack = append(stack, res.Infos[i].Path)
}
}

resourceInfos = append(resourceInfos, res.Infos...)

if depth != "infinity" {
break
}

// TODO: stream response to avoid storing too many results in memory
}
}

Expand Down