From 49d6b792a15ea55e6aefc986397791b52c591179 Mon Sep 17 00:00:00 2001 From: Michael Barz Date: Fri, 25 Mar 2022 15:48:24 +0100 Subject: [PATCH] move Metadata to the share pkg --- internal/grpc/services/gateway/usershareprovider.go | 6 +++--- .../sharesstorageprovider/sharesstorageprovider.go | 9 +++++---- pkg/share/share.go | 7 +++++++ pkg/utils/utils.go | 6 ------ 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/internal/grpc/services/gateway/usershareprovider.go b/internal/grpc/services/gateway/usershareprovider.go index f5b66a1fa61..deb7c744451 100644 --- a/internal/grpc/services/gateway/usershareprovider.go +++ b/internal/grpc/services/gateway/usershareprovider.go @@ -32,9 +32,9 @@ import ( "github.com/cs3org/reva/v2/pkg/errtypes" "github.com/cs3org/reva/v2/pkg/rgrpc/status" "github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool" + "github.com/cs3org/reva/v2/pkg/share" "github.com/cs3org/reva/v2/pkg/storage/utils/grants" rtrace "github.com/cs3org/reva/v2/pkg/trace" - "github.com/cs3org/reva/v2/pkg/utils" "github.com/pkg/errors" ) @@ -167,7 +167,7 @@ func (s *svc) ListReceivedShares(ctx context.Context, req *collaboration.ListRec // TODO: This is a hack for now. // Can we do that cleaner somehow? // The `ListStorageSpaces` method in sharesstorageprovider/sharesstorageprovider.go needs the etags. - shareMetaData := make(map[string]utils.ShareMetadata, len(res.Shares)) + shareMetaData := make(map[string]share.Metadata, len(res.Shares)) for _, rs := range res.Shares { sRes, err := s.Stat(ctx, &provider.StatRequest{Ref: &provider.Reference{ResourceId: rs.Share.ResourceId}}) if err != nil { @@ -183,7 +183,7 @@ func (s *svc) ListReceivedShares(ctx context.Context, req *collaboration.ListRec Msg("ListRecievedShares: failed to stat the resource") continue } - shareMetaData[rs.Share.Id.OpaqueId] = utils.ShareMetadata{ETag: sRes.Info.Etag, Mtime: sRes.Info.Mtime} + shareMetaData[rs.Share.Id.OpaqueId] = share.Metadata{ETag: sRes.Info.Etag, Mtime: sRes.Info.Mtime} } marshalled, err := json.Marshal(shareMetaData) diff --git a/internal/grpc/services/sharesstorageprovider/sharesstorageprovider.go b/internal/grpc/services/sharesstorageprovider/sharesstorageprovider.go index 9303f80a33a..1d67f6cd31e 100644 --- a/internal/grpc/services/sharesstorageprovider/sharesstorageprovider.go +++ b/internal/grpc/services/sharesstorageprovider/sharesstorageprovider.go @@ -25,6 +25,7 @@ import ( "path/filepath" "strings" + "github.com/cs3org/reva/v2/pkg/share" "google.golang.org/grpc" codes "google.golang.org/grpc/codes" gstatus "google.golang.org/grpc/status" @@ -359,7 +360,7 @@ func (s *service) ListStorageSpaces(ctx context.Context, req *provider.ListStora } var receivedShares []*collaboration.ReceivedShare - var shareMd map[string]utils.ShareMetadata + var shareMd map[string]share.Metadata var err error if fetchShares { receivedShares, shareMd, err = s.fetchShares(ctx) @@ -931,7 +932,7 @@ func (s *service) rejectReceivedShare(ctx context.Context, receivedShare *collab return errtypes.NewErrtypeFromStatus(res.Status) } -func (s *service) fetchShares(ctx context.Context) ([]*collaboration.ReceivedShare, map[string]utils.ShareMetadata, error) { +func (s *service) fetchShares(ctx context.Context) ([]*collaboration.ReceivedShare, map[string]share.Metadata, error) { lsRes, err := s.gateway.ListReceivedShares(ctx, &collaboration.ListReceivedSharesRequest{ // FIXME filter by received shares for resource id - listing all shares is tooo expensive! }) @@ -943,7 +944,7 @@ func (s *service) fetchShares(ctx context.Context) ([]*collaboration.ReceivedSha } receivedShares := lsRes.Shares - var shareMd map[string]utils.ShareMetadata + var shareMd map[string]share.Metadata if lsRes.Opaque != nil { if entry, ok := lsRes.Opaque.Map["shareMetadata"]; ok { // If we can't get the etags thats fine, just continue. @@ -953,7 +954,7 @@ func (s *service) fetchShares(ctx context.Context) ([]*collaboration.ReceivedSha return receivedShares, shareMd, nil } -func findEarliestShare(receivedShares []*collaboration.ReceivedShare, shareMd map[string]utils.ShareMetadata) (earliestShare *collaboration.Share, atLeastOneAccepted bool) { +func findEarliestShare(receivedShares []*collaboration.ReceivedShare, shareMd map[string]share.Metadata) (earliestShare *collaboration.Share, atLeastOneAccepted bool) { for _, rs := range receivedShares { var hasCurrentMd bool var hasEarliestMd bool diff --git a/pkg/share/share.go b/pkg/share/share.go index 2c4755dd586..5b6f1a55563 100644 --- a/pkg/share/share.go +++ b/pkg/share/share.go @@ -24,6 +24,7 @@ import ( userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" + types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" "github.com/cs3org/reva/v2/internal/http/services/owncloud/ocs/conversions" "github.com/cs3org/reva/v2/pkg/utils" "google.golang.org/genproto/protobuf/field_mask" @@ -37,6 +38,12 @@ const ( //go:generate mockery -name Manager +// Metadata contains Metadata for a share +type Metadata struct { + ETag string + Mtime *types.Timestamp +} + // Manager is the interface that manipulates shares. type Manager interface { // Create a new share in fn with the given acl. diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 1720626fc6c..4e31bd9c17b 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -66,12 +66,6 @@ var ( errInvalidSpaceReference = errors.New("invalid storage space reference") ) -// ShareMetadata contains Metadata for a share -type ShareMetadata struct { - ETag string - Mtime *types.Timestamp -} - // Skip evaluates whether a source endpoint contains any of the prefixes. // i.e: /a/b/c/d/e contains prefix /a/b/c func Skip(source string, prefixes []string) bool {