Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sharestorageprovider: Stat resource when resolving share by path #4561

Merged
merged 3 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions changelog/unreleased/fix-stat-recreated-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Bugfix: Fix Stat() by Path on re-created resource

We fixed bug that caused Stat Requests using a Path reference to a mount point
in the sharejail to not resolve correctly, when a share using the same
mount point to an already deleted resource was still existing.

https://github.com/cs3org/reva/pull/4561
https://github.com/owncloud/ocis/issues/7895
Original file line number Diff line number Diff line change
Expand Up @@ -1057,11 +1057,11 @@ func (s *service) resolveAcceptedShare(ctx context.Context, ref *provider.Refere
return lsRes.Share, lsRes.Status, nil
}

// we currently need to list all shares and match the path if the request is relative to the share jail root
// we currently need to list all accepted shares and match the path if the
// request is relative to the share jail root. Also we need to Stat() the
// shared resource's id to check whether that still exist. There might be
// old shares using the same path but for an already vanished resource id.
if ref.ResourceId.OpaqueId == utils.ShareStorageProviderID && ref.Path != "." {
// we need to list accepted shares and match the path

// look up share for this resourceid
lsRes, err := sharingCollaborationClient.ListReceivedShares(ctx, &collaboration.ListReceivedSharesRequest{
Filters: []*collaboration.Filter{
{
Expand All @@ -1080,15 +1080,32 @@ func (s *service) resolveAcceptedShare(ctx context.Context, ref *provider.Refere
return nil, lsRes.Status, nil
}
for _, receivedShare := range lsRes.Shares {
// make sure to skip unaccepted shares
if receivedShare.State != collaboration.ShareState_SHARE_STATE_ACCEPTED {
continue
}
if isMountPointForPath(receivedShare.MountPoint.Path, ref.Path) {
// Only return this share if the resource still exists.
gatewayClient, err := s.gatewaySelector.Next()
if err != nil {
return nil, nil, err
}
sRes, err := gatewayClient.Stat(ctx, &provider.StatRequest{
Ref: &provider.Reference{ResourceId: receivedShare.GetShare().GetResourceId()},
})
if err != nil {
appctx.GetLogger(ctx).Debug().
Err(err).
Interface("resourceID", receivedShare.GetShare().GetResourceId()).
Msg("resolveAcceptedShare: failed to stat shared resource")
continue
}
if sRes.Status.Code != rpc.Code_CODE_OK {
appctx.GetLogger(ctx).Debug().
Interface("resourceID", receivedShare.GetShare().GetResourceId()).
Interface("status", sRes.Status).
Msg("resolveAcceptedShare: failed to stat shared resource")
continue
}
return receivedShare, lsRes.Status, nil
}
}

}

return nil, status.NewNotFound(ctx, "sharesstorageprovider: not found "+ref.String()), nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,23 @@ var _ = Describe("Sharesstorageprovider", func() {
},
}
default:
if req.Ref.ResourceId.OpaqueId == "shareddir-merged" {
switch req.Ref.ResourceId.OpaqueId {
case "shareddir", "shareddir2":
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to provide the constants for the "shareddir", "shareddir2", "shareddir-merged"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the surrounding code, especially the outer switch statement, I'd say: no 😃

More seriously I guess the mocks could benefit from some refactoring, but I think the string constants are the least of on an issue.

permissionSet := &sprovider.ResourcePermissions{
Stat: true,
ListContainer: true,
}
return &sprovider.StatResponse{
Status: status.NewOK(context.Background()),
Info: &sprovider.ResourceInfo{
Type: sprovider.ResourceType_RESOURCE_TYPE_CONTAINER,
Path: "share1-shareddir",
Id: req.Ref.ResourceId,
PermissionSet: permissionSet,
Size: 100,
},
}
case "shareddir-merged":
permissionSet := &sprovider.ResourcePermissions{
Stat: true,
ListContainer: true,
Expand All @@ -280,9 +296,10 @@ var _ = Describe("Sharesstorageprovider", func() {
Size: 100,
},
}
}
return &sprovider.StatResponse{
Status: status.NewNotFound(context.Background(), "not found"),
default:
return &sprovider.StatResponse{
Status: status.NewNotFound(context.Background(), "not found"),
}
}
}
},
Expand Down
Loading