From 8d39de861af323901313dde749c6d89a0e11dd67 Mon Sep 17 00:00:00 2001 From: Ralf Haferkamp Date: Thu, 15 Jun 2023 16:08:11 +0200 Subject: [PATCH 1/2] demposedfs: Fix ReadNode call in NodeFromSpaceID() Pass the correct ID (the spaced id) to ReadNode(). Also fix the signature of the NodeFromSpaceID method to make it more obvious that just needs a Resource ID. --- pkg/storage/utils/decomposedfs/lookup/lookup.go | 8 ++++---- pkg/storage/utils/decomposedfs/node/node_test.go | 6 +++--- pkg/storage/utils/decomposedfs/recycle.go | 2 +- pkg/storage/utils/decomposedfs/upload/processing.go | 5 +---- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/pkg/storage/utils/decomposedfs/lookup/lookup.go b/pkg/storage/utils/decomposedfs/lookup/lookup.go index 395559eb36..c2ae2bfdcc 100644 --- a/pkg/storage/utils/decomposedfs/lookup/lookup.go +++ b/pkg/storage/utils/decomposedfs/lookup/lookup.go @@ -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) } @@ -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 } diff --git a/pkg/storage/utils/decomposedfs/node/node_test.go b/pkg/storage/utils/decomposedfs/node/node_test.go index 982d3ba143..070f641304 100644 --- a/pkg/storage/utils/decomposedfs/node/node_test.go +++ b/pkg/storage/utils/decomposedfs/node/node_test.go @@ -231,7 +231,7 @@ 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())) @@ -239,7 +239,7 @@ var _ = Describe("Node", func() { 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{ @@ -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() diff --git a/pkg/storage/utils/decomposedfs/recycle.go b/pkg/storage/utils/decomposedfs/recycle.go index 8cbbc120fa..8163f4d03a 100644 --- a/pkg/storage/utils/decomposedfs/recycle.go +++ b/pkg/storage/utils/decomposedfs/recycle.go @@ -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 } diff --git a/pkg/storage/utils/decomposedfs/upload/processing.go b/pkg/storage/utils/decomposedfs/upload/processing.go index 1af0cfb6e4..06d92907a2 100644 --- a/pkg/storage/utils/decomposedfs/upload/processing.go +++ b/pkg/storage/utils/decomposedfs/upload/processing.go @@ -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") } From ff34129471f9d4602c3200488e8b56a6998cdc90 Mon Sep 17 00:00:00 2001 From: Ralf Haferkamp Date: Thu, 15 Jun 2023 16:13:44 +0200 Subject: [PATCH 2/2] demposedfs: Fix ListFolder to have the correct SpaceRoot in the results ListFolder passed the wrong node for the SpaceRoot parameter to ReadNode() --- changelog/unreleased/decomposedfs-spacelookup-overflow.md | 3 +++ pkg/storage/utils/decomposedfs/tree/tree.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 changelog/unreleased/decomposedfs-spacelookup-overflow.md diff --git a/changelog/unreleased/decomposedfs-spacelookup-overflow.md b/changelog/unreleased/decomposedfs-spacelookup-overflow.md new file mode 100644 index 0000000000..6d11d1f688 --- /dev/null +++ b/changelog/unreleased/decomposedfs-spacelookup-overflow.md @@ -0,0 +1,3 @@ +Bugfix: fixed couple of smaller space lookup issues + +https://github.com/cs3org/reva/pull/3982 diff --git a/pkg/storage/utils/decomposedfs/tree/tree.go b/pkg/storage/utils/decomposedfs/tree/tree.go index 5ab6d69af5..3d35de034f 100644 --- a/pkg/storage/utils/decomposedfs/tree/tree.go +++ b/pkg/storage/utils/decomposedfs/tree/tree.go @@ -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 }