Skip to content

Commit

Permalink
fix logic when removing share with commit enabled (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
labkode committed Aug 19, 2019
1 parent 73e83cd commit ae3f230
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
38 changes: 22 additions & 16 deletions cmd/revad/svcs/grpcsvcs/gatewaysvc/usershareprovidersvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,9 @@ func (s *svc) RemoveShare(ctx context.Context, req *usershareproviderv0alphapb.R
}, nil
}

res, err := c.RemoveShare(ctx, req)
if err != nil {
return nil, errors.Wrap(err, "gatewaysvc: error calling RemoveShare")
}

// if we don't need to commit we return earlier
if !s.c.CommitShareToStorageGrant && !s.c.CommitShareToStorageRef {
return res, nil
}

// TODO(labkode): if both commits are enabled they could be done concurrently.
if s.c.CommitShareToStorageGrant {
// if we need to commit the share, we need the resource it points to.
var share *usershareproviderv0alphapb.Share
if s.c.CommitShareToStorageGrant || s.c.CommitShareToStorageRef {
getShareReq := &usershareproviderv0alphapb.GetShareRequest{
Ref: req.Ref,
}
Expand All @@ -119,22 +110,37 @@ func (s *svc) RemoveShare(ctx context.Context, req *usershareproviderv0alphapb.R

if getShareRes.Status.Code != rpcpb.Code_CODE_OK {
res := &usershareproviderv0alphapb.RemoveShareResponse{
Status: status.NewInternal(ctx, "error getting share when committing to the share"),
Status: status.NewInternal(ctx, "error getting share when committing to the storage"),
}
return res, nil
}
share = getShareRes.Share
}

res, err := c.RemoveShare(ctx, req)
if err != nil {
return nil, errors.Wrap(err, "gatewaysvc: error calling RemoveShare")
}

// if we don't need to commit we return earlier
if !s.c.CommitShareToStorageGrant && !s.c.CommitShareToStorageRef {
return res, nil
}

// TODO(labkode): if both commits are enabled they could be done concurrently.
if s.c.CommitShareToStorageGrant {
grantReq := &storageproviderv0alphapb.RemoveGrantRequest{
Ref: &storageproviderv0alphapb.Reference{
Spec: &storageproviderv0alphapb.Reference_Id{
Id: getShareRes.Share.ResourceId,
Id: share.ResourceId,
},
},
Grant: &storageproviderv0alphapb.Grant{
Grantee: getShareRes.Share.Grantee,
Permissions: getShareRes.Share.Permissions.Permissions,
Grantee: share.Grantee,
Permissions: share.Permissions.Permissions,
},
}

grantRes, err := s.RemoveGrant(ctx, grantReq)
if err != nil {
return nil, errors.Wrap(err, "gatewaysvc: error calling RemoveGrant")
Expand Down
2 changes: 1 addition & 1 deletion pkg/share/manager/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (m *manager) get(ctx context.Context, ref *usershareproviderv0alphapb.Share
}

if err != nil {
return s, err
return nil, err
}

// check if we are the owner
Expand Down

0 comments on commit ae3f230

Please sign in to comment.