Skip to content

Commit

Permalink
Provide total transfer size with the datatx protocol (cs3org#3891)
Browse files Browse the repository at this point in the history
* Provide total file size with the datatx protocol

* Lint fix

---------

Co-authored-by: Antoon P <[email protected]>
  • Loading branch information
2 people authored and gmgigi96 committed Jun 28, 2023
1 parent 504aac7 commit 194532c
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 += info.Size
}
return nil
})
if err != nil {
panic(err)
}
return &ocmd.Datatx{
SourceURI: s.webdavURL(ctx, share),
Size: 0,
Size: 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 194532c

Please sign in to comment.