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

decomposedfs: make owner type optional #1978

Merged
merged 1 commit into from
Aug 9, 2021
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
5 changes: 5 additions & 0 deletions changelog/unreleased/owner-type-is-optional.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: owner type is optional

When reading the user from the extended attributes the user type might not be set, in this case we now return a user with an invalid type, which correctly reflects the state on disk.

https://github.com/cs3org/reva/pull/1978
55 changes: 33 additions & 22 deletions pkg/storage/utils/decomposedfs/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,45 +270,56 @@ func (n *Node) Parent() (p *Node, err error) {

// Owner returns the cached owner id or reads it from the extended attributes
// TODO can be private as only the AsResourceInfo uses it
func (n *Node) Owner() (o *userpb.UserId, err error) {
func (n *Node) Owner() (*userpb.UserId, error) {
if n.owner != nil {
return n.owner, nil
}

owner := &userpb.UserId{}

// FIXME ... do we return the owner of the reference or the owner of the target?
// we don't really know the owner of the target ... and as the reference may point anywhere we cannot really find out
// but what are the permissions? all? none? the gateway has to fill in?
// TODO what if this is a reference?
nodePath := n.InternalPath()
// lookup parent id in extended attributes
var attrBytes []byte
var err error
// lookup ID in extended attributes
if attrBytes, err = xattr.Get(nodePath, xattrs.OwnerIDAttr); err == nil {
if n.owner == nil {
n.owner = &userpb.UserId{}
}
n.owner.OpaqueId = string(attrBytes)
} else {
return
attrBytes, err = xattr.Get(nodePath, xattrs.OwnerIDAttr)
switch {
case err == nil:
owner.OpaqueId = string(attrBytes)
case isNoData(err), isNotFound(err):
fallthrough
default:
return nil, err
}

// lookup IDP in extended attributes
if attrBytes, err = xattr.Get(nodePath, xattrs.OwnerIDPAttr); err == nil {
if n.owner == nil {
n.owner = &userpb.UserId{}
}
n.owner.Idp = string(attrBytes)
} else {
return
attrBytes, err = xattr.Get(nodePath, xattrs.OwnerIDPAttr)
switch {
case err == nil:
owner.Idp = string(attrBytes)
case isNoData(err), isNotFound(err):
fallthrough
default:
return nil, err
}

// lookup type in extended attributes
if attrBytes, err = xattr.Get(nodePath, xattrs.OwnerTypeAttr); err == nil {
if n.owner == nil {
n.owner = &userpb.UserId{}
}
n.owner.Type = utils.UserTypeMap(string(attrBytes))
} else {
return
attrBytes, err = xattr.Get(nodePath, xattrs.OwnerTypeAttr)
switch {
case err == nil:
owner.Type = utils.UserTypeMap(string(attrBytes))
case isNoData(err), isNotFound(err):
fallthrough
default:
// TODO the user type defaults to invalid, which is the case
err = nil
}

n.owner = owner
return n.owner, err
}

Expand Down