From 8d222fe896a00d673518b446754e742428ded692 Mon Sep 17 00:00:00 2001 From: Antoon P Date: Wed, 17 May 2023 14:41:04 +0200 Subject: [PATCH] Provide total transfer size with the datatx protocol (#3891) * Provide total file size with the datatx protocol * Lint fix --------- Co-authored-by: Antoon P --- changelog/unreleased/datatx-transfer-size.md | 4 +++ .../ocmshareprovider/ocmshareprovider.go | 33 +++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 changelog/unreleased/datatx-transfer-size.md diff --git a/changelog/unreleased/datatx-transfer-size.md b/changelog/unreleased/datatx-transfer-size.md new file mode 100644 index 00000000000..7820fc7b8ba --- /dev/null +++ b/changelog/unreleased/datatx-transfer-size.md @@ -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 \ No newline at end of file diff --git a/internal/grpc/services/ocmshareprovider/ocmshareprovider.go b/internal/grpc/services/ocmshareprovider/ocmshareprovider.go index 37b0307545a..88e11393d98 100644 --- a/internal/grpc/services/ocmshareprovider/ocmshareprovider.go +++ b/internal/grpc/services/ocmshareprovider/ocmshareprovider.go @@ -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" @@ -71,6 +72,7 @@ type service struct { client *client.OCMClient gateway gateway.GatewayAPIClient webappTmpl *template.Template + walker walker.Walker } func (c *config) init() { @@ -134,6 +136,7 @@ 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, @@ -141,6 +144,7 @@ func New(m map[string]interface{}, ss *grpc.Server) (rgrpc.Service, error) { client: client, gateway: gateway, webappTmpl: tpl, + walker: walker, } return service, nil @@ -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 {