Skip to content

Commit

Permalink
Merge pull request #1 from PVince81/public-shares
Browse files Browse the repository at this point in the history
  • Loading branch information
refs authored May 27, 2020
2 parents a07b579 + 39f3fc5 commit 7fd06cf
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions internal/http/services/owncloud/ocdav/propfind.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,33 +97,48 @@ func (s *svc) handlePropfind(w http.ResponseWriter, r *http.Request, ns string)

info := res.Info
infos := []*provider.ResourceInfo{info}
if info.Type == provider.ResourceType_RESOURCE_TYPE_CONTAINER && depth != "0" {
if info.Type == provider.ResourceType_RESOURCE_TYPE_CONTAINER && depth == "1" {
req := &provider.ListContainerRequest{
Ref: ref,
}
res, err := client.ListContainer(ctx, req)
if err != nil {
log.Error().Err(err).Msg("error sending list container grpc request")
w.WriteHeader(http.StatusInternalServerError)
return
}

if res.Status.Code != rpc.Code_CODE_OK {
log.Err(err).Msg("error calling grpc list container")
w.WriteHeader(http.StatusInternalServerError)
return
}
infos = append(infos, res.Infos...)
} else if depth == "infinity" {
// FIXME: doesn't work cross-storage as the results will have the wrong paths!
// use a stack to explore sub-containers breadth-first
stack := []*provider.ResourceInfo{info}
stack := []string{info.Path}
for len(stack) > 0 {
// retrieve path on top of stack
nextInfo := stack[len(stack)-1]
path := stack[len(stack)-1]
ref = &provider.Reference{
Spec: &provider.Reference_Path{Path: path},
}
req := &provider.ListContainerRequest{
Ref: ref,
}
res, err := client.ListContainer(ctx, req)
if err != nil {
log.Error().Err(err).Str("path", nextInfo.Path).Msg("error sending list container grpc request")
log.Error().Err(err).Str("path", path).Msg("error sending list container grpc request")
w.WriteHeader(http.StatusInternalServerError)
return
}
if res.Status.Code != rpc.Code_CODE_OK {
log.Err(err).Str("path", nextInfo.Path).Msg("error calling grpc list container")
log.Err(err).Str("path", path).Msg("error calling grpc list container")
w.WriteHeader(http.StatusInternalServerError)
return
}

ref = &provider.Reference{
Spec: &provider.Reference_Id{
Id: nextInfo.Id,
},
}

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

if depth != "infinity" {
Expand All @@ -139,7 +154,7 @@ func (s *svc) handlePropfind(w http.ResponseWriter, r *http.Request, ns string)
for i := len(res.Infos) - 1; i >= 0; i-- {
//for i := range res.Infos {
if res.Infos[i].Type == provider.ResourceType_RESOURCE_TYPE_CONTAINER {
stack = append(stack, res.Infos[i])
stack = append(stack, res.Infos[i].Path)
}
}
}
Expand Down

0 comments on commit 7fd06cf

Please sign in to comment.