Skip to content

Commit

Permalink
fix the mount points naming
Browse files Browse the repository at this point in the history
  • Loading branch information
2403905 committed Mar 7, 2024
1 parent 78b252a commit 1641f69
Show file tree
Hide file tree
Showing 22 changed files with 137 additions and 207 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/fix-mount-points-naming.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Fix the mount points naming

We fixed a bug that caused inconsistent naming when multiple users share the resource with same name to another user.

https://github.com/owncloud/ocis/pull/8543
https://github.com/owncloud/ocis/issues/8471
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/coreos/go-oidc/v3 v3.9.0
github.com/cs3org/go-cs3apis v0.0.0-20231023073225-7748710e0781
github.com/cs3org/reva/v2 v2.19.1
github.com/cs3org/reva/v2 v2.19.2-0.20240307063856-698d86209c3d
github.com/dhowden/tag v0.0.0-20230630033851-978a0926ee25
github.com/disintegration/imaging v1.6.2
github.com/dutchcoders/go-clamd v0.0.0-20170520113014-b970184f4d9e
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1019,8 +1019,8 @@ github.com/crewjam/saml v0.4.14 h1:g9FBNx62osKusnFzs3QTN5L9CVA/Egfgm+stJShzw/c=
github.com/crewjam/saml v0.4.14/go.mod h1:UVSZCf18jJkk6GpWNVqcyQJMD5HsRugBPf4I1nl2mME=
github.com/cs3org/go-cs3apis v0.0.0-20231023073225-7748710e0781 h1:BUdwkIlf8IS2FasrrPg8gGPHQPOrQ18MS1Oew2tmGtY=
github.com/cs3org/go-cs3apis v0.0.0-20231023073225-7748710e0781/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cs3org/reva/v2 v2.19.1 h1:XryNNOSw+ogmJGIf6UA44eB3NZCd/z7o5aoiRaTnLd0=
github.com/cs3org/reva/v2 v2.19.1/go.mod h1:GRUrOp5HbFVwZTgR9bVrMZ/MvVy+Jhxw1PdMmhhKP9E=
github.com/cs3org/reva/v2 v2.19.2-0.20240307063856-698d86209c3d h1:ru/ebNMHDU0SJ9CyzYY9uHMpFXGXT4cDaAh6zib4xPg=
github.com/cs3org/reva/v2 v2.19.2-0.20240307063856-698d86209c3d/go.mod h1:GRUrOp5HbFVwZTgR9bVrMZ/MvVy+Jhxw1PdMmhhKP9E=
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg=
github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
Expand Down
54 changes: 29 additions & 25 deletions services/frontend/pkg/command/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"path"
"path/filepath"
"sort"
"slices"
"strconv"
"strings"

Expand Down Expand Up @@ -171,49 +171,53 @@ func getMountpoint(ctx context.Context, l log.Logger, itemid *provider.ResourceI
// we need to sort the received shares by mount point in order to make things easier to evaluate.
base := path.Base(info.GetPath())
mount := base
mountedShares := make([]*collaboration.ReceivedShare, 0, len(lrs.Shares))
mounts := make([]string, 0, len(lrs.Shares))
var exists bool

for _, s := range lrs.Shares {
if s.State != collaboration.ShareState_SHARE_STATE_ACCEPTED {
// we don't care about unaccepted shares
continue
}

if utils.ResourceIDEqual(s.Share.ResourceId, itemid) {
if utils.ResourceIDEqual(s.GetShare().GetResourceId(), itemid) {
// a share to the same resource already exists and is mounted
return s.MountPoint.Path, nil
return s.GetMountPoint().GetPath(), nil
}

mountedShares = append(mountedShares, s)
}

sort.Slice(mountedShares, func(i, j int) bool {
return mountedShares[i].MountPoint.Path > mountedShares[j].MountPoint.Path
})

// now we have a list of shares, we want to iterate over all of them and check for name collisions
for i, ms := range mountedShares {
if ms.MountPoint.Path == mount {
if s.GetMountPoint().GetPath() == mount {
// does the shared resource still exist?
gwc, err := gatewaySelector.Next()
if err != nil {
l.Error().Err(err).Msg("cannot get gateway client")
continue
}
_, err = utils.GetResourceByID(ctx, ms.Share.ResourceId, gwc)
_, err = utils.GetResourceByID(ctx, s.GetShare().GetResourceId(), gwc)
if err == nil {
// The mount point really already exists, we need to insert a number into the filename
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 = fmt.Sprintf("%s (%s)%s", name, strconv.Itoa(i+1), ext)
exists = true
}
// TODO we could delete shares here if the stat returns code NOT FOUND ... but listening for file deletes would be better
}
// collect all mount points
mounts = append(mounts, s.GetMountPoint().GetPath())
}

// If the mount point really already exists, we need to insert a number into the filename
if exists {
// 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(mounts)+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
if !slices.Contains(mounts, mount) {
return mount, nil
}
}
}
return mount, nil
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1641f69

Please sign in to comment.