Skip to content

Commit

Permalink
move Metadata to the share pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
micbar committed Mar 25, 2022
1 parent e35a9a4 commit 49d6b79
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
6 changes: 3 additions & 3 deletions internal/grpc/services/gateway/usershareprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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!
})
Expand All @@ -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.
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions pkg/share/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand Down
6 changes: 0 additions & 6 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 49d6b79

Please sign in to comment.