@@ -520,12 +520,7 @@ func (s *service) UpdateReceivedShare(ctx context.Context, req *collaboration.Up
520
520
isMountPointSet := slices .Contains (req .GetUpdateMask ().GetPaths (), _fieldMaskPathMountPoint ) && req .GetShare ().GetMountPoint ().GetPath () != ""
521
521
// we calculate a valid mountpoint only if the share should be accepted and the mount point is not set explicitly
522
522
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 )
529
524
switch {
530
525
case err != nil :
531
526
fallthrough
@@ -556,7 +551,11 @@ func (s *service) UpdateReceivedShare(ctx context.Context, req *collaboration.Up
556
551
}
557
552
}
558
553
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
+ }
560
559
receivedShare , err := gwc .GetReceivedShare (ctx , & collaboration.GetReceivedShareRequest {
561
560
Ref : & collaboration.ShareReference {
562
561
Spec : & collaboration.ShareReference_Id {
@@ -575,6 +574,10 @@ func setReceivedShareMountPoint(ctx context.Context, gwc gateway.GatewayAPIClien
575
574
return status .NewOK (ctx ), nil
576
575
}
577
576
577
+ gwc , err = s .gatewaySelector .Next ()
578
+ if err != nil {
579
+ return nil , err
580
+ }
578
581
resourceStat , err := gwc .Stat (ctx , & provider.StatRequest {
579
582
Ref : & provider.Reference {
580
583
ResourceId : receivedShare .GetShare ().GetShare ().GetResourceId (),
@@ -592,11 +595,15 @@ func setReceivedShareMountPoint(ctx context.Context, gwc gateway.GatewayAPIClien
592
595
var userID * userpb.UserId
593
596
_ = utils .ReadJSONFromOpaque (req .Opaque , "userid" , & userID )
594
597
598
+ receivedShares , err := s .sm .ListReceivedShares (ctx , []* collaboration.Filter {}, userID )
599
+ if err != nil {
600
+ return nil , err
601
+ }
602
+
595
603
// 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 ,
597
605
resourceStat .GetInfo ().GetId (),
598
606
resourceStat .GetInfo ().GetName (),
599
- userID ,
600
607
)
601
608
if err != nil {
602
609
return status .NewInternal (ctx , err .Error ()), nil
@@ -620,7 +627,6 @@ func GetMountpointAndUnmountedShares(ctx context.Context, gwc gateway.GatewayAPI
620
627
if userId != nil {
621
628
listReceivedSharesReq .Opaque = utils .AppendJSONToOpaque (nil , "userid" , userId )
622
629
}
623
-
624
630
listReceivedSharesRes , err := gwc .ListReceivedShares (ctx , listReceivedSharesReq )
625
631
if err != nil {
626
632
return "" , nil , errtypes .InternalError ("grpc list received shares request failed" )
@@ -630,17 +636,30 @@ func GetMountpointAndUnmountedShares(ctx context.Context, gwc gateway.GatewayAPI
630
636
return "" , nil , err
631
637
}
632
638
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
+
633
645
unmountedShares := []* collaboration.ReceivedShare {}
634
646
base := filepath .Clean (name )
635
647
mount := base
636
648
existingMountpoint := ""
637
- mountedShares := make ([]string , 0 , len (listReceivedSharesRes . GetShares () ))
649
+ mountedShares := make ([]string , 0 , len (receivedShares ))
638
650
var pathExists bool
651
+ var err error
639
652
640
- for _ , s := range listReceivedSharesRes . GetShares () {
653
+ for _ , s := range receivedShares {
641
654
resourceIDEqual := utils .ResourceIDEqual (s .GetShare ().GetResourceId (), id )
642
655
643
656
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
+ }
644
663
// a share to the resource already exists and is mounted, remembers the mount point
645
664
_ , err := utils .GetResourceByID (ctx , s .GetShare ().GetResourceId (), gwc )
646
665
if err == nil {
@@ -658,6 +677,12 @@ func GetMountpointAndUnmountedShares(ctx context.Context, gwc gateway.GatewayAPI
658
677
mountedShares = append (mountedShares , s .GetMountPoint ().GetPath ())
659
678
if s .GetMountPoint ().GetPath () == mount {
660
679
// 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
+ }
661
686
_ , err := utils .GetResourceByID (ctx , s .GetShare ().GetResourceId (), gwc )
662
687
if err == nil {
663
688
pathExists = true
0 commit comments