Skip to content

Commit

Permalink
Relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Mar 23, 2021
1 parent f7c6426 commit 7c4fbb1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
26 changes: 22 additions & 4 deletions internal/grpc/services/gateway/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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{
Expand All @@ -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,
Expand Down
17 changes: 13 additions & 4 deletions internal/http/services/owncloud/ocs/handlers/cloud/users/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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,
},
},
})
Expand Down

0 comments on commit 7c4fbb1

Please sign in to comment.