Skip to content

Commit

Permalink
Spaceroots (#3440)
Browse files Browse the repository at this point in the history
* Use the space name as the node name for space roots

* Set a proper path for space roots

* Add changelog

* Fix tests
  • Loading branch information
aduffeck committed Nov 10, 2022
1 parent 32d6aee commit 370f798
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/fix-spaceroots.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions pkg/storage/utils/decomposedfs/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkg/storage/utils/decomposedfs/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions tests/integration/grpc/gateway_storageprovider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)))
})

Expand Down

0 comments on commit 370f798

Please sign in to comment.