From 39f3fc55bb4db152a7fa8ee9f935aed841e1f857 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Wed, 27 May 2020 17:00:12 +0200 Subject: [PATCH] Fix PROPFIND with Depth 1 Use original ref for Depth 1 which works fine. Depth infinity will have its own logic which currently only works within a single storage. --- .../http/services/owncloud/ocdav/propfind.go | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/internal/http/services/owncloud/ocdav/propfind.go b/internal/http/services/owncloud/ocdav/propfind.go index c6196f65c9..f6d7d4423f 100644 --- a/internal/http/services/owncloud/ocdav/propfind.go +++ b/internal/http/services/owncloud/ocdav/propfind.go @@ -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" { @@ -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) } } }