diff --git a/changelog/unreleased/fix-spaceroots.md b/changelog/unreleased/fix-spaceroots.md new file mode 100644 index 0000000000..4611340202 --- /dev/null +++ b/changelog/unreleased/fix-spaceroots.md @@ -0,0 +1,5 @@ +Bugfix: Set proper names and paths for space roots + +We fixed a problem where the names and paths were not set correctly for space roots. + +https://github.com/cs3org/reva/pull/3440 diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go index 8a94b91af1..83df7da5e6 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go @@ -1178,6 +1178,9 @@ func (h *Handler) addFileInfo(ctx context.Context, s *conversions.ShareData, inf s.FileTarget = path.Join(h.sharePrefix, name) if s.ShareType == conversions.ShareTypePublicLink { s.FileTarget = path.Join("/", name) + if info.Id.OpaqueId == info.Id.SpaceId { // we unfortunately have to special case space roots and not append their name here + s.FileTarget = "/" + } } } s.StorageID = storageIDPrefix + s.FileTarget diff --git a/pkg/storage/utils/decomposedfs/node/node.go b/pkg/storage/utils/decomposedfs/node/node.go index fa05e41da2..04acdf444f 100644 --- a/pkg/storage/utils/decomposedfs/node/node.go +++ b/pkg/storage/utils/decomposedfs/node/node.go @@ -191,6 +191,14 @@ func ReadNode(ctx context.Context, lu PathLookup, spaceID, nodeID string, canLis case err != nil: return nil, err } + // lookup name in extended attributes + r.Name, err = r.Xattr(xattrs.NameAttr) + switch { + case xattrs.IsNotExist(err): + return r, nil // swallow not found, the node defaults to exists = false + case err != nil: + return nil, err + } r.Exists = true // TODO ReadNode should not check permissions @@ -605,9 +613,12 @@ func (n *Node) AsResourceInfo(ctx context.Context, rp *provider.ResourcePermissi id := &provider.ResourceId{SpaceId: n.SpaceID, OpaqueId: n.ID} - if returnBasename { + switch { + case n.IsSpaceRoot(): + fn = "." // space roots do not have a path as they are referencing themselves + case returnBasename: fn = n.Name - } else { + default: fn, err = n.lu.Path(ctx, n) if err != nil { return nil, err diff --git a/pkg/storage/utils/decomposedfs/spaces.go b/pkg/storage/utils/decomposedfs/spaces.go index 96678b149e..efc04a389f 100644 --- a/pkg/storage/utils/decomposedfs/spaces.go +++ b/pkg/storage/utils/decomposedfs/spaces.go @@ -121,6 +121,7 @@ func (fs *Decomposedfs) CreateStorageSpace(ctx context.Context, req *provider.Cr // always enable propagation on the storage space root // mark the space root node as the end of propagation metadata[xattrs.PropagationAttr] = "1" + metadata[xattrs.NameAttr] = req.Name metadata[xattrs.SpaceNameAttr] = req.Name if req.Type != "" { @@ -528,6 +529,7 @@ func (fs *Decomposedfs) UpdateStorageSpace(ctx context.Context, req *provider.Up metadata := make(map[string]string, 5) if space.Name != "" { + metadata[xattrs.NameAttr] = space.Name metadata[xattrs.SpaceNameAttr] = space.Name } diff --git a/tests/integration/grpc/gateway_storageprovider_test.go b/tests/integration/grpc/gateway_storageprovider_test.go index 60df3f8b8d..8ea003ca9c 100644 --- a/tests/integration/grpc/gateway_storageprovider_test.go +++ b/tests/integration/grpc/gateway_storageprovider_test.go @@ -477,7 +477,7 @@ var _ = Describe("gateway", func() { info := statRes.Info Expect(info.Type).To(Equal(storagep.ResourceType_RESOURCE_TYPE_CONTAINER)) Expect(utils.ResourceIDEqual(info.Id, homeRef.ResourceId)).To(BeTrue()) - Expect(info.Path).To(Equal("")) // path of a root node of a space is always "" + Expect(info.Path).To(Equal(".")) // path of a root node of a space is always "." Expect(info.Owner.OpaqueId).To(Equal(user.Id.OpaqueId)) // TODO: size aggregating is done by the client now - so no chance testing that here @@ -492,7 +492,7 @@ var _ = Describe("gateway", func() { info := statRes.Info Expect(info.Type).To(Equal(storagep.ResourceType_RESOURCE_TYPE_CONTAINER)) Expect(utils.ResourceIDEqual(info.Id, embeddedRef.ResourceId)).To(BeTrue()) - Expect(info.Path).To(Equal("")) // path of a root node of a space is always "" + Expect(info.Path).To(Equal(".")) // path of a root node of a space is always "." Expect(info.Size).To(Equal(uint64(2))) })