Skip to content

Commit

Permalink
fix propfinds for spaces (#2254)
Browse files Browse the repository at this point in the history
  • Loading branch information
David Christofas authored Nov 16, 2021
1 parent d69d908 commit f812bfb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
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 @@ -124,11 +125,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 @@ -256,6 +261,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 @@ -314,9 +323,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 @@ -330,24 +348,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

0 comments on commit f812bfb

Please sign in to comment.