Skip to content

Commit

Permalink
fix dav spaces copy
Browse files Browse the repository at this point in the history
  • Loading branch information
David Christofas committed Jun 23, 2021
1 parent a80e3f0 commit 6118f18
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
3 changes: 1 addition & 2 deletions internal/grpc/services/gateway/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,6 @@ func (s *svc) stat(ctx context.Context, req *provider.StatRequest) (*provider.St
if err != nil || rsp.Status.Code != rpc.Code_CODE_OK {
return rsp, err
}

return rsp, nil
}

Expand Down Expand Up @@ -1614,7 +1613,7 @@ func (s *svc) listContainerOnProvider(ctx context.Context, req *provider.ListCon
if utils.IsAbsoluteReference(req.Ref) {
resPath := path.Clean(req.Ref.GetPath())
newPath := req.Ref.GetPath()
if resPath != "" && !strings.HasPrefix(resPath, p.ProviderPath) {
if resPath != "." && !strings.HasPrefix(resPath, p.ProviderPath) {
newPath = p.ProviderPath
}
req.Ref = &provider.Reference{Path: newPath}
Expand Down
21 changes: 11 additions & 10 deletions internal/http/services/owncloud/ocdav/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/cs3org/reva/pkg/appctx"
"github.com/cs3org/reva/pkg/rhttp"
"github.com/cs3org/reva/pkg/rhttp/router"
"github.com/cs3org/reva/pkg/utils"
"github.com/pkg/errors"
"github.com/rs/zerolog"
"go.opencensus.io/trace"
Expand Down Expand Up @@ -235,7 +236,7 @@ func (s *svc) handleSpacesCopy(w http.ResponseWriter, r *http.Request, spaceID s
return
}

sublog := appctx.GetLogger(ctx).With().Str("spaceid", spaceID).Str("path", r.URL.Path).Logger()
sublog := appctx.GetLogger(ctx).With().Str("spaceid", spaceID).Str("path", r.URL.Path).Str("destination", dst).Logger()

// retrieve a specific storage space
srcRef, status, err := s.lookUpStorageSpaceReference(ctx, spaceID, r.URL.Path)
Expand Down Expand Up @@ -293,7 +294,6 @@ func (s *svc) handleSpacesCopy(w http.ResponseWriter, r *http.Request, spaceID s
func (s *svc) executeSpacesCopy(ctx context.Context, client gateway.GatewayAPIClient, src *provider.ResourceInfo, dst *provider.Reference, recurse bool) error {
log := appctx.GetLogger(ctx)
log.Debug().Str("src", src.Path).Interface("dst", dst).Msg("descending")

if src.Type == provider.ResourceType_RESOURCE_TYPE_CONTAINER {
// create dir
createReq := &provider.CreateContainerRequest{
Expand All @@ -311,7 +311,8 @@ func (s *svc) executeSpacesCopy(ctx context.Context, client gateway.GatewayAPICl
}

// descend for children
listReq := &provider.ListContainerRequest{Ref: &provider.Reference{ResourceId: src.Id}}
// explicitly work with relative references
listReq := &provider.ListContainerRequest{Ref: &provider.Reference{ResourceId: src.Id, Path: "."}}
res, err := client.ListContainer(ctx, listReq)
if err != nil {
return err
Expand All @@ -321,10 +322,9 @@ func (s *svc) executeSpacesCopy(ctx context.Context, client gateway.GatewayAPICl
}

for i := range res.Infos {
childPath := strings.TrimPrefix(res.Infos[i].Path, src.Path)
childRef := &provider.Reference{
ResourceId: src.Id,
Path: path.Join(dst.Path, childPath),
ResourceId: dst.ResourceId,
Path: utils.MakeRelativePath(path.Join(dst.Path, res.Infos[i].Path)),
}
err := s.executeSpacesCopy(ctx, client, res.Infos[i], childRef, recurse)
if err != nil {
Expand All @@ -336,8 +336,8 @@ func (s *svc) executeSpacesCopy(ctx context.Context, client gateway.GatewayAPICl
// copy file

// 1. get download url

dReq := &provider.InitiateFileDownloadRequest{Ref: &provider.Reference{ResourceId: src.Id}}
// explicitly work with relative references so that we will use the spaces datatx
dReq := &provider.InitiateFileDownloadRequest{Ref: &provider.Reference{ResourceId: src.Id, Path: "."}}

dRes, err := client.InitiateFileDownload(ctx, dReq)
if err != nil {
Expand All @@ -354,7 +354,6 @@ func (s *svc) executeSpacesCopy(ctx context.Context, client gateway.GatewayAPICl
downloadEP, downloadToken = p.DownloadEndpoint, p.Token
}
}

// 2. get upload url

uReq := &provider.InitiateFileUploadRequest{
Expand Down Expand Up @@ -392,7 +391,9 @@ func (s *svc) executeSpacesCopy(ctx context.Context, client gateway.GatewayAPICl
if err != nil {
return err
}
httpDownloadReq.Header.Set(datagateway.TokenTransportHeader, downloadToken)
if downloadToken != "" {
httpDownloadReq.Header.Set(datagateway.TokenTransportHeader, downloadToken)
}

httpDownloadRes, err := s.client.Do(httpDownloadReq)
if err != nil {
Expand Down

0 comments on commit 6118f18

Please sign in to comment.