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

fixed couple of smaller space lookup issues #3982

Merged
merged 2 commits into from
Jun 19, 2023
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
3 changes: 3 additions & 0 deletions changelog/unreleased/decomposedfs-spacelookup-overflow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Bugfix: fixed couple of smaller space lookup issues

https://github.com/cs3org/reva/pull/3982
8 changes: 4 additions & 4 deletions pkg/storage/utils/decomposedfs/lookup/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (lu *Lookup) NodeFromID(ctx context.Context, id *provider.ResourceId) (n *n
}
if id.OpaqueId == "" {
// The Resource references the root of a space
return lu.NodeFromSpaceID(ctx, id)
return lu.NodeFromSpaceID(ctx, id.SpaceId)
}
return node.ReadNode(ctx, lu, id.SpaceId, id.OpaqueId, false, nil, false)
}
Expand All @@ -162,9 +162,9 @@ func Pathify(id string, depth, width int) string {
return b.String()
}

// NodeFromSpaceID converts a resource id without an opaque id into a Node
func (lu *Lookup) NodeFromSpaceID(ctx context.Context, id *provider.ResourceId) (n *node.Node, err error) {
node, err := node.ReadNode(ctx, lu, id.SpaceId, id.OpaqueId, false, nil, false)
// NodeFromSpaceID converts a resource id into a Node
func (lu *Lookup) NodeFromSpaceID(ctx context.Context, spaceID string) (n *node.Node, err error) {
node, err := node.ReadNode(ctx, lu, spaceID, spaceID, false, nil, false)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/storage/utils/decomposedfs/node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,15 @@ var _ = Describe("Node", func() {
})
Describe("Permissions", func() {
It("Checks the owner permissions on a personal space", func() {
node1, err := env.Lookup.NodeFromSpaceID(env.Ctx, env.SpaceRootRes)
node1, err := env.Lookup.NodeFromSpaceID(env.Ctx, env.SpaceRootRes.SpaceId)
Expect(err).ToNot(HaveOccurred())
perms, _ := node1.PermissionSet(env.Ctx)
Expect(perms).To(Equal(node.OwnerPermissions()))
})
It("Checks the manager permissions on a project space", func() {
pSpace, err := env.CreateTestStorageSpace("project", &provider.Quota{QuotaMaxBytes: 2000})
Expect(err).ToNot(HaveOccurred())
nodePSpace, err := env.Lookup.NodeFromSpaceID(env.Ctx, pSpace)
nodePSpace, err := env.Lookup.NodeFromSpaceID(env.Ctx, pSpace.SpaceId)
Expect(err).ToNot(HaveOccurred())
u := ctxpkg.ContextMustGetUser(env.Ctx)
env.Permissions.On("AssemblePermissions", mock.Anything, mock.Anything, mock.Anything).Return(provider.ResourcePermissions{
Expand Down Expand Up @@ -288,7 +288,7 @@ var _ = Describe("Node", func() {
Permissions: ocsconv.NewEditorRole(false).CS3ResourcePermissions(),
})
Expect(err).ToNot(HaveOccurred())
spaceRoot, err := env.Lookup.NodeFromSpaceID(env.Ctx, storageSpace)
spaceRoot, err := env.Lookup.NodeFromSpaceID(env.Ctx, storageSpace.SpaceId)
Expect(err).ToNot(HaveOccurred())
permissionsActual, _ := spaceRoot.PermissionSet(env.Ctx)
permissionsExpected := ocsconv.NewEditorRole(false).CS3ResourcePermissions()
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/utils/decomposedfs/recycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (fs *Decomposedfs) ListRecycle(ctx context.Context, ref *provider.Reference
sublog := appctx.GetLogger(ctx).With().Str("space", spaceID).Str("key", key).Str("relative_path", relativePath).Logger()

// check permissions
trashnode, err := fs.lu.NodeFromSpaceID(ctx, ref.ResourceId)
trashnode, err := fs.lu.NodeFromSpaceID(ctx, spaceID)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/utils/decomposedfs/tree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ func (t *Tree) ListFolder(ctx context.Context, n *node.Node) ([]*node.Node, erro
}
}

child, err := node.ReadNode(ctx, t.lookup, n.SpaceID, nodeID, false, n, true)
child, err := node.ReadNode(ctx, t.lookup, n.SpaceID, nodeID, false, n.SpaceRoot, true)
if err != nil {
return err
}
Expand Down
5 changes: 1 addition & 4 deletions pkg/storage/utils/decomposedfs/upload/processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ func New(ctx context.Context, info tusd.FileInfo, lu *lookup.Lookup, tp Tree, p
return nil, errors.New("Decomposedfs: missing dir in metadata")
}

n, err := lu.NodeFromSpaceID(ctx, &provider.ResourceId{
SpaceId: info.Storage["SpaceRoot"],
OpaqueId: info.Storage["SpaceRoot"],
})
n, err := lu.NodeFromSpaceID(ctx, info.Storage["SpaceRoot"])
if err != nil {
return nil, errors.Wrap(err, "Decomposedfs: error getting space root node")
}
Expand Down