Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,8 @@ func (s *service) Delete(ctx context.Context, req *provider.DeleteRequest) (*pro
}, nil
}

// the root of a share always has the path "."
if req.Ref.ResourceId.StorageId == utils.ShareStorageProviderID && req.Ref.ResourceId.SpaceId == utils.ShareStorageSpaceID && req.Ref.Path == "." {
// deleting the root of a share rejects it instead of deleting the owner's resource
if isShareRoot(req.Ref, receivedShare) {
err := s.rejectReceivedShare(ctx, receivedShare)
if err != nil {
return &provider.DeleteResponse{
Expand Down Expand Up @@ -1337,6 +1337,16 @@ func isRename(s, d *provider.Reference) bool {
isShareJailRoot(d.ResourceId) && len(strings.SplitN(d.Path, "/", 3)) == 2
}

// isShareRoot checks if the reference points at the root of the received share,
// either by the share id with the path "." or by its mount point relative to the share jail, e.g. './renamed'
func isShareRoot(ref *provider.Reference, s *collaboration.ReceivedShare) bool {
if isShareJailChild(ref.ResourceId) {
return ref.Path == "."
}
return isShareJailRoot(ref.ResourceId) &&
filepath.Clean(strings.TrimPrefix(ref.Path, "./")) == filepath.Clean(strings.TrimPrefix(s.GetMountPoint().GetPath(), "./"))
}

func isShareJailChild(id *provider.ResourceId) bool {
return id.SpaceId == utils.ShareStorageSpaceID && id.OpaqueId != utils.ShareStorageSpaceID
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,24 @@ var _ = Describe("Sharesstorageprovider", func() {
sharingCollaborationClient.AssertCalled(GinkgoT(), "UpdateReceivedShare", mock.Anything, mock.Anything)
})

It("rejects the share when deleting a share by its mount point", func() {
sharingCollaborationClient.On("UpdateReceivedShare", mock.Anything, mock.Anything).Return(
&collaboration.UpdateReceivedShareResponse{Status: status.NewOK(ctx)}, nil)
req := &sprovider.DeleteRequest{
Ref: &sprovider.Reference{
ResourceId: ShareJail,
Path: "./share1-shareddir",
},
}
res, err := s.Delete(ctx, req)
gatewayClient.AssertNotCalled(GinkgoT(), "Delete", mock.Anything, mock.Anything)
Expect(err).ToNot(HaveOccurred())
Expect(res).ToNot(BeNil())
Expect(res.Status.Code).To(Equal(rpc.Code_CODE_OK))

sharingCollaborationClient.AssertCalled(GinkgoT(), "UpdateReceivedShare", mock.Anything, mock.Anything)
})

It("deletes a file", func() {
req := &sprovider.DeleteRequest{
Ref: &sprovider.Reference{
Expand Down
Loading