Skip to content

Commit 86812e7

Browse files
committed
Use manager to list shares
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
1 parent 8ffaada commit 86812e7

File tree

2 files changed

+42
-12
lines changed

2 files changed

+42
-12
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Bugfix: Use manager to list shares
2+
3+
When updating a received share the usershareprovider now uses the share manager directly to list received shares instead of going through the gateway again.
4+
5+
https://github.com/cs3org/reva/pull/4971

internal/grpc/services/usershareprovider/usershareprovider.go

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -520,12 +520,7 @@ func (s *service) UpdateReceivedShare(ctx context.Context, req *collaboration.Up
520520
isMountPointSet := slices.Contains(req.GetUpdateMask().GetPaths(), _fieldMaskPathMountPoint) && req.GetShare().GetMountPoint().GetPath() != ""
521521
// we calculate a valid mountpoint only if the share should be accepted and the mount point is not set explicitly
522522
if isStateTransitionShareAccepted && !isMountPointSet {
523-
gatewayClient, err := s.gatewaySelector.Next()
524-
if err != nil {
525-
return nil, err
526-
}
527-
528-
s, err := setReceivedShareMountPoint(ctx, gatewayClient, req)
523+
s, err := s.setReceivedShareMountPoint(ctx, req)
529524
switch {
530525
case err != nil:
531526
fallthrough
@@ -556,7 +551,11 @@ func (s *service) UpdateReceivedShare(ctx context.Context, req *collaboration.Up
556551
}
557552
}
558553

559-
func setReceivedShareMountPoint(ctx context.Context, gwc gateway.GatewayAPIClient, req *collaboration.UpdateReceivedShareRequest) (*rpc.Status, error) {
554+
func (s *service) setReceivedShareMountPoint(ctx context.Context, req *collaboration.UpdateReceivedShareRequest) (*rpc.Status, error) {
555+
gwc, err := s.gatewaySelector.Next()
556+
if err != nil {
557+
return nil, err
558+
}
560559
receivedShare, err := gwc.GetReceivedShare(ctx, &collaboration.GetReceivedShareRequest{
561560
Ref: &collaboration.ShareReference{
562561
Spec: &collaboration.ShareReference_Id{
@@ -575,6 +574,10 @@ func setReceivedShareMountPoint(ctx context.Context, gwc gateway.GatewayAPIClien
575574
return status.NewOK(ctx), nil
576575
}
577576

577+
gwc, err = s.gatewaySelector.Next()
578+
if err != nil {
579+
return nil, err
580+
}
578581
resourceStat, err := gwc.Stat(ctx, &provider.StatRequest{
579582
Ref: &provider.Reference{
580583
ResourceId: receivedShare.GetShare().GetShare().GetResourceId(),
@@ -592,11 +595,15 @@ func setReceivedShareMountPoint(ctx context.Context, gwc gateway.GatewayAPIClien
592595
var userID *userpb.UserId
593596
_ = utils.ReadJSONFromOpaque(req.Opaque, "userid", &userID)
594597

598+
receivedShares, err := s.sm.ListReceivedShares(ctx, []*collaboration.Filter{}, userID)
599+
if err != nil {
600+
return nil, err
601+
}
602+
595603
// check if the requested mount point is available and if not, find a suitable one
596-
availableMountpoint, _, err := GetMountpointAndUnmountedShares(ctx, gwc,
604+
availableMountpoint, _, err := getMountpointAndUnmountedShares(ctx, receivedShares, s.gatewaySelector, nil,
597605
resourceStat.GetInfo().GetId(),
598606
resourceStat.GetInfo().GetName(),
599-
userID,
600607
)
601608
if err != nil {
602609
return status.NewInternal(ctx, err.Error()), nil
@@ -620,7 +627,6 @@ func GetMountpointAndUnmountedShares(ctx context.Context, gwc gateway.GatewayAPI
620627
if userId != nil {
621628
listReceivedSharesReq.Opaque = utils.AppendJSONToOpaque(nil, "userid", userId)
622629
}
623-
624630
listReceivedSharesRes, err := gwc.ListReceivedShares(ctx, listReceivedSharesReq)
625631
if err != nil {
626632
return "", nil, errtypes.InternalError("grpc list received shares request failed")
@@ -630,17 +636,30 @@ func GetMountpointAndUnmountedShares(ctx context.Context, gwc gateway.GatewayAPI
630636
return "", nil, err
631637
}
632638

639+
return getMountpointAndUnmountedShares(ctx, listReceivedSharesRes.GetShares(), nil, gwc, id, name)
640+
}
641+
642+
// GetMountpointAndUnmountedShares returns a new or existing mountpoint for the given info and produces a list of unmounted received shares for the same resource
643+
func getMountpointAndUnmountedShares(ctx context.Context, receivedShares []*collaboration.ReceivedShare, gatewaySelector pool.Selectable[gateway.GatewayAPIClient], gwc gateway.GatewayAPIClient, id *provider.ResourceId, name string) (string, []*collaboration.ReceivedShare, error) {
644+
633645
unmountedShares := []*collaboration.ReceivedShare{}
634646
base := filepath.Clean(name)
635647
mount := base
636648
existingMountpoint := ""
637-
mountedShares := make([]string, 0, len(listReceivedSharesRes.GetShares()))
649+
mountedShares := make([]string, 0, len(receivedShares))
638650
var pathExists bool
651+
var err error
639652

640-
for _, s := range listReceivedSharesRes.GetShares() {
653+
for _, s := range receivedShares {
641654
resourceIDEqual := utils.ResourceIDEqual(s.GetShare().GetResourceId(), id)
642655

643656
if resourceIDEqual && s.State == collaboration.ShareState_SHARE_STATE_ACCEPTED {
657+
if gatewaySelector != nil {
658+
gwc, err = gatewaySelector.Next()
659+
if err != nil {
660+
return "", nil, err
661+
}
662+
}
644663
// a share to the resource already exists and is mounted, remembers the mount point
645664
_, err := utils.GetResourceByID(ctx, s.GetShare().GetResourceId(), gwc)
646665
if err == nil {
@@ -658,6 +677,12 @@ func GetMountpointAndUnmountedShares(ctx context.Context, gwc gateway.GatewayAPI
658677
mountedShares = append(mountedShares, s.GetMountPoint().GetPath())
659678
if s.GetMountPoint().GetPath() == mount {
660679
// does the shared resource still exist?
680+
if gatewaySelector != nil {
681+
gwc, err = gatewaySelector.Next()
682+
if err != nil {
683+
return "", nil, err
684+
}
685+
}
661686
_, err := utils.GetResourceByID(ctx, s.GetShare().GetResourceId(), gwc)
662687
if err == nil {
663688
pathExists = true

0 commit comments

Comments
 (0)