Skip to content

Commit

Permalink
Provide total file size with the datatx protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
antoonp committed May 16, 2023
1 parent 2be8a61 commit 675e715
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
4 changes: 4 additions & 0 deletions changelog/unreleased/datatx-transfer-size.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Enhancement: Provide data transfer size with datatx share

https://github.com/cs3org/reva/pull/3891
https://github.com/cs3org/reva/issues/2104
33 changes: 31 additions & 2 deletions internal/grpc/services/ocmshareprovider/ocmshareprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
"github.com/cs3org/reva/pkg/rgrpc/status"
"github.com/cs3org/reva/pkg/rgrpc/todo/pool"
"github.com/cs3org/reva/pkg/sharedconf"
"github.com/cs3org/reva/pkg/storage/utils/walker"
"github.com/cs3org/reva/pkg/utils"
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
Expand Down Expand Up @@ -71,6 +72,7 @@ type service struct {
client *client.OCMClient
gateway gateway.GatewayAPIClient
webappTmpl *template.Template
walker walker.Walker
}

func (c *config) init() {
Expand Down Expand Up @@ -134,13 +136,15 @@ func New(m map[string]interface{}, ss *grpc.Server) (rgrpc.Service, error) {
if err != nil {
return nil, err
}
walker := walker.NewWalker(gateway)

service := &service{
conf: c,
repo: repo,
client: client,
gateway: gateway,
webappTmpl: tpl,
walker: walker,
}

return service, nil
Expand Down Expand Up @@ -210,13 +214,38 @@ func (s *service) getWebappProtocol(share *ocm.Share) *ocmd.Webapp {
}

func (s *service) getDataTransferProtocol(ctx context.Context, share *ocm.Share) *ocmd.Datatx {
// TODO discover the size
var size uint64
// get the path of the share
statRes, err := s.gateway.Stat(ctx, &providerpb.StatRequest{
Ref: &providerpb.Reference{
ResourceId: share.ResourceId,
},
})
if err != nil {
panic(err)
}

path := statRes.GetInfo().Path
err = s.walk(ctx, path, func(path string, info *providerpb.ResourceInfo, err error) error {
if info.Type == providerpb.ResourceType_RESOURCE_TYPE_FILE {
size = size + uint64(info.Size)
}
return nil
})
if err != nil {
panic(err)
}
return &ocmd.Datatx{
SourceURI: s.webdavURL(ctx, share),
Size: 0,
Size: uint64(size),
}
}

// walk traverses the path recursively to discover all resources in the tree
func (s *service) walk(ctx context.Context, path string, fn walker.WalkFunc) error {
return s.walker.Walk(ctx, path, fn)
}

func (s *service) getProtocols(ctx context.Context, share *ocm.Share) ocmd.Protocols {
var p ocmd.Protocols
for _, m := range share.AccessMethods {
Expand Down

0 comments on commit 675e715

Please sign in to comment.