From 7c4fbb10b6d7dd5beac103d11f7a517db8f7dc58 Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Tue, 23 Mar 2021 17:14:07 +0100 Subject: [PATCH] Relative paths --- .../grpc/services/gateway/storageprovider.go | 26 ++++++++++++++++--- .../ocs/handlers/cloud/users/users.go | 17 +++++++++--- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/internal/grpc/services/gateway/storageprovider.go b/internal/grpc/services/gateway/storageprovider.go index 866055e24b3..f4367ada029 100644 --- a/internal/grpc/services/gateway/storageprovider.go +++ b/internal/grpc/services/gateway/storageprovider.go @@ -1518,6 +1518,7 @@ func (s *svc) listContainer(ctx context.Context, req *provider.ListContainerRequ } var infos []*provider.ResourceInfo + indirects := make(map[string][]*provider.ResourceInfo) for _, p := range providers { c, err := s.getStorageProviderClient(ctx, p) @@ -1527,7 +1528,7 @@ func (s *svc) listContainer(ctx context.Context, req *provider.ListContainerRequ }, nil } - resPath := req.Ref.GetPath() + resPath := path.Clean(req.Ref.GetPath()) if resPath != "" && !strings.HasPrefix(resPath, p.ProviderPath) { req = &provider.ListContainerRequest{ Ref: &provider.Reference{ @@ -1542,13 +1543,30 @@ func (s *svc) listContainer(ctx context.Context, req *provider.ListContainerRequ return nil, errors.Wrap(err, "gateway: error calling ListContainer") } for _, inf := range res.Infos { - if parent := path.Dir(inf.Path); resPath != "" && path.Clean(resPath) != parent { - continue + if parent := path.Dir(inf.Path); resPath != "" && resPath != parent { + parts := strings.Split(strings.TrimPrefix(inf.Path, resPath), "/") + p := path.Join(resPath, parts[1]) + indirects[p] = append(indirects[p], inf) + } else { + infos = append(infos, inf) } - infos = append(infos, inf) } } + for k, v := range indirects { + inf := &provider.ResourceInfo{ + Id: &provider.ResourceId{ + StorageId: "/", + OpaqueId: uuid.New().String(), + }, + Type: provider.ResourceType_RESOURCE_TYPE_CONTAINER, + Etag: etag.GenerateEtagFromResources(nil, v), + Path: k, + Size: 0, + } + infos = append(infos, inf) + } + return &provider.ListContainerResponse{ Status: status.NewOK(ctx), Infos: infos, diff --git a/internal/http/services/owncloud/ocs/handlers/cloud/users/users.go b/internal/http/services/owncloud/ocs/handlers/cloud/users/users.go index 2278f500923..89538d075ee 100644 --- a/internal/http/services/owncloud/ocs/handlers/cloud/users/users.go +++ b/internal/http/services/owncloud/ocs/handlers/cloud/users/users.go @@ -37,14 +37,12 @@ import ( // Handler renders user data for the user id given in the url path type Handler struct { - gatewayAddr string - homeNamespace string + gatewayAddr string } // Init initializes this and any contained handlers func (h *Handler) Init(c *config.Config) error { h.gatewayAddr = c.GatewaySvc - h.homeNamespace = c.HomeNamespace return nil } @@ -117,10 +115,21 @@ func (h *Handler) handleUsers(w http.ResponseWriter, r *http.Request, u *userpb. return } + getHomeRes, err := gc.GetHome(ctx, &provider.GetHomeRequest{}) + if err != nil { + sublog.Error().Err(err).Msg("error calling GetHome") + w.WriteHeader(http.StatusInternalServerError) + return + } + if getHomeRes.Status.Code != rpc.Code_CODE_OK { + ocdav.HandleErrorStatus(sublog, w, getHomeRes.Status) + return + } + getQuotaRes, err := gc.GetQuota(ctx, &gateway.GetQuotaRequest{ Ref: &provider.Reference{ Spec: &provider.Reference_Path{ - Path: h.homeNamespace, + Path: getHomeRes.Path, }, }, })