Skip to content

Commit

Permalink
add constants for space types and root node id
Browse files Browse the repository at this point in the history
  • Loading branch information
David Christofas committed Feb 11, 2022
1 parent 68e5ec7 commit 9e40105
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pkg/storage/utils/decomposedfs/decomposedfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func (fs *Decomposedfs) CreateHome(ctx context.Context) (err error) {
}

// add storage space
if err := fs.createStorageSpace(ctx, "personal", h.ID); err != nil {
if err := fs.createStorageSpace(ctx, spaceTypePersonal, h.ID); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/utils/decomposedfs/grants.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (fs *Decomposedfs) AddGrant(ctx context.Context, ref *provider.Reference, g

// when a grant is added to a space, do not add a new space under "shares"
if spaceGrant := ctx.Value(utils.SpaceGrant); spaceGrant == nil {
err := fs.createStorageSpace(ctx, "share", node.ID)
err := fs.createStorageSpace(ctx, spaceTypeShare, node.ID)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/utils/decomposedfs/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (lu *Lookup) Path(ctx context.Context, n *node.Node) (p string, err error)

// RootNode returns the root node of the storage
func (lu *Lookup) RootNode(ctx context.Context) (*node.Node, error) {
n := node.New("root", "", "", 0, "", nil, lu)
n := node.New(node.RootID, "", "", 0, "", nil, lu)
n.Exists = true
return n, nil
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/storage/utils/decomposedfs/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ const (

// TrashIDDelimiter represents the characters used to separate the nodeid and the deletion time.
TrashIDDelimiter = ".T."

// RootID defines the root node's ID
RootID = "root"
)

// Node represents a node in the tree and provides methods to get a Parent or Child instance
Expand Down Expand Up @@ -817,7 +820,7 @@ func (n *Node) ReadUserPermissions(ctx context.Context, u *userpb.User) (ap prov
if o.OpaqueId == "" {
// this happens for root nodes and project spaces in the storage. the extended attributes are set to emptystring to indicate: no owner
// for project spaces we need to go over the grants and check the granted permissions
if n.ID == "root" {
if n.ID == RootID {
return NoOwnerPermissions(), nil
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/utils/decomposedfs/node/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (p *Permissions) AssemblePermissions(ctx context.Context, n *Node) (ap prov
if o.OpaqueId == "" {
// this happens for root nodes and project spaces in the storage. the extended attributes are set to emptystring to indicate: no owner
// for project spaces we need to go over the grants and check the granted permissions
if n.ID == "root" {
if n.ID == RootID {
return NoOwnerPermissions(), nil
}
}
Expand Down Expand Up @@ -282,7 +282,7 @@ func (p *Permissions) getUserAndPermissions(ctx context.Context, n *Node) (*user
if o.OpaqueId == "" {
// this happens for root nodes and project spaces in the storage. the extended attributes are set to emptystring to indicate: no owner
// for project spaces we need to go over the grants and check the granted permissions
if n.ID != "root" {
if n.ID != RootID {
return u, nil
}
perms := NoOwnerPermissions()
Expand Down
17 changes: 10 additions & 7 deletions pkg/storage/utils/decomposedfs/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ import (
)

const (
spaceTypeAny = "*"
spaceIDAny = "*"
spaceTypePersonal = "personal"
spaceTypeProject = "project"
spaceTypeShare = "share"
spaceTypeAny = "*"
spaceIDAny = "*"
)

// CreateStorageSpace creates a storage space
Expand All @@ -70,7 +73,7 @@ func (fs *Decomposedfs) CreateStorageSpace(ctx context.Context, req *provider.Cr
}
// TODO enforce a uuid?
// TODO clarify if we want to enforce a single personal storage space or if we want to allow sending the spaceid
if req.Type == "personal" {
if req.Type == spaceTypePersonal {
spaceID = req.Owner.Id.OpaqueId
}

Expand Down Expand Up @@ -105,7 +108,7 @@ func (fs *Decomposedfs) CreateStorageSpace(ctx context.Context, req *provider.Cr
}

ownerID := u.Id
if req.Type == "project" {
if req.Type == spaceTypeProject {
ownerID = &userv1beta1.UserId{}
}

Expand Down Expand Up @@ -147,7 +150,7 @@ func (fs *Decomposedfs) CreateStorageSpace(ctx context.Context, req *provider.Cr
},
}

if req.Type != "project" {
if req.Type != spaceTypeProject {
resp.StorageSpace.Owner = u
}

Expand Down Expand Up @@ -283,7 +286,7 @@ func (fs *Decomposedfs) ListStorageSpaces(ctx context.Context, filter []*provide
spaceType := filepath.Base(filepath.Dir(matches[i]))

// FIXME type share evolved to grant on the edge branch ... make it configurable if the driver should support them or not for now ... ignore type share
if spaceType == "share" {
if spaceType == spaceTypeShare {
numShares++
// do not list shares as spaces for the owner
continue
Expand Down Expand Up @@ -471,7 +474,7 @@ func (fs *Decomposedfs) DeleteStorageSpace(ctx context.Context, req *provider.De
return err
}

matches, err = filepath.Glob(filepath.Join(fs.o.Root, "nodes", "root", req.Id.OpaqueId+node.TrashIDDelimiter+"*"))
matches, err = filepath.Glob(filepath.Join(fs.o.Root, "nodes", node.RootID, req.Id.OpaqueId+node.TrashIDDelimiter+"*"))
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/utils/decomposedfs/tree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (t *Tree) Setup(owner *userpb.UserId, propagateToRoot bool) error {

// the root node has an empty name
// the root node has no parent
n := node.New("root", "", "", 0, "", nil, t.lookup)
n := node.New(node.RootID, "", "", 0, "", nil, t.lookup)
err := t.createNode(n, owner)
if err != nil {
return err
Expand Down Expand Up @@ -207,7 +207,7 @@ func (t *Tree) linkSpace(spaceType, spaceID, nodeID string) {

func isRootNode(nodePath string) bool {
attrBytes, err := xattr.Get(nodePath, xattrs.ParentidAttr)
return err == nil && string(attrBytes) == "root"
return err == nil && string(attrBytes) == node.RootID
}
func isSharedNode(nodePath string) bool {
if attrs, err := xattr.List(nodePath); err == nil {
Expand Down

0 comments on commit 9e40105

Please sign in to comment.