Skip to content

Commit

Permalink
fix: remove unnecessary share validations and cleanup mountpoint name…
Browse files Browse the repository at this point in the history
… func
  • Loading branch information
fschade committed Jun 10, 2024
1 parent ebe67f9 commit 15bb511
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 53 deletions.
33 changes: 4 additions & 29 deletions internal/grpc/services/usershareprovider/usershareprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,24 +506,6 @@ func (s *service) GetReceivedShare(ctx context.Context, req *collaboration.GetRe
}

func (s *service) UpdateReceivedShare(ctx context.Context, req *collaboration.UpdateReceivedShareRequest) (*collaboration.UpdateReceivedShareResponse, error) {
if req.GetShare() == nil {
return &collaboration.UpdateReceivedShareResponse{
Status: status.NewInvalid(ctx, "updating requires a received share object"),
}, nil
}

if req.GetShare().GetShare() == nil {
return &collaboration.UpdateReceivedShareResponse{
Status: status.NewInvalid(ctx, "share missing"),
}, nil
}

if req.GetShare().GetShare().GetId() == nil {
return &collaboration.UpdateReceivedShareResponse{
Status: status.NewInvalid(ctx, "share id missing"),
}, nil
}

if req.GetShare().GetShare().GetId().GetOpaqueId() == "" {
return &collaboration.UpdateReceivedShareResponse{
Status: status.NewInvalid(ctx, "share id empty"),
Expand Down Expand Up @@ -627,9 +609,7 @@ func GetAvailableMountpoint(ctx context.Context, gwc gateway.GatewayAPIClient, i
return "", err
}

// we need to sort the received shares by mount point in order to make things easier to evaluate.
base := filepath.Clean(name)
mount := base
mount := filepath.Clean(name)
existingMountpoint := ""
mountedShares := make([]string, 0, len(listReceivedSharesRes.GetShares()))
var pathExists bool
Expand Down Expand Up @@ -668,14 +648,9 @@ func GetAvailableMountpoint(ctx context.Context, gwc gateway.GatewayAPIClient, i
if pathExists {
// now we have a list of shares, we want to iterate over all of them and check for name collisions agents a mount points list
for i := 1; i <= len(mountedShares)+1; i++ {
ext := filepath.Ext(base)
name := strings.TrimSuffix(base, ext)
// be smart about .tar.(gz|bz) files
if strings.HasSuffix(name, ".tar") {
name = strings.TrimSuffix(name, ".tar")
ext = ".tar" + ext
}
mount = name + " (" + strconv.Itoa(i) + ")" + ext
ext := filepath.Ext(mount)
mount = strings.TrimSuffix(mount, ext) + " (" + strconv.Itoa(i) + ")" + ext

if !slices.Contains(mountedShares, mount) {
return mount, nil
}
Expand Down
24 changes: 0 additions & 24 deletions internal/grpc/services/usershareprovider/usershareprovider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,30 +141,6 @@ var _ = Describe("user share provider service", func() {
Expect(res.GetStatus().GetCode()).To(Equal(expectedStatus.GetCode()))
Expect(res.GetStatus().GetMessage()).To(ContainSubstring(expectedStatus.GetMessage()))
},
Entry(
"no received share",
&collaborationpb.UpdateReceivedShareRequest{},
status.NewInvalid(ctx, "updating requires"),
nil,
),
Entry(
"no share",
&collaborationpb.UpdateReceivedShareRequest{
Share: &collaborationpb.ReceivedShare{},
},
status.NewInvalid(ctx, "share missing"),
nil,
),
Entry(
"no share id",
&collaborationpb.UpdateReceivedShareRequest{
Share: &collaborationpb.ReceivedShare{
Share: &collaborationpb.Share{},
},
},
status.NewInvalid(ctx, "share id missing"),
nil,
),
Entry(
"no share opaque id",
&collaborationpb.UpdateReceivedShareRequest{
Expand Down

0 comments on commit 15bb511

Please sign in to comment.