Skip to content

Commit

Permalink
Revert "eosbinary: do not use version folders for xattrs any longer (c…
Browse files Browse the repository at this point in the history
…s3org#4520)"

This reverts commit b99ad48.
  • Loading branch information
glpatcern committed May 8, 2024
1 parent be2ce5f commit 8d46b0e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 13 deletions.
6 changes: 0 additions & 6 deletions changelog/unreleased/eos-xattr.md

This file was deleted.

62 changes: 55 additions & 7 deletions pkg/eosclient/eosbinary/eosbinary.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,22 @@ func (c *Client) getRawFileInfoByPath(ctx context.Context, auth eosclient.Author

func (c *Client) mergeACLsAndAttrsForFiles(ctx context.Context, auth eosclient.Authorization, info *eosclient.FileInfo) *eosclient.FileInfo {
// We need to inherit the ACLs for the parent directory as these are not available for files
// And the attributes from the version folders
if !info.IsDir {
parentInfo, err := c.getRawFileInfoByPath(ctx, auth, path.Dir(info.File))
// Even if this call fails, at least return the current file object
if err == nil {
info.SysACL.Entries = append(info.SysACL.Entries, parentInfo.SysACL.Entries...)
}

// We need to merge attrs set for the version folders, so get those resolved for the current user
versionFolderInfo, err := c.GetFileInfoByPath(ctx, auth, getVersionFolder(info.File))
if err == nil {
info.SysACL.Entries = append(info.SysACL.Entries, versionFolderInfo.SysACL.Entries...)
for k, v := range versionFolderInfo.Attrs {
info.Attrs[k] = v
}
}
}

return info
Expand All @@ -460,12 +470,23 @@ func (c *Client) SetAttr(ctx context.Context, auth eosclient.Authorization, attr
return errors.New("eos: attr is invalid: " + serializeAttribute(attr))
}

// Favorites need to be stored per user so handle these separately
if attr.Type == eosclient.UserAttr && attr.Key == favoritesKey {
info, err := c.getRawFileInfoByPath(ctx, auth, path)
var info *eosclient.FileInfo
var err error
// We need to set the attrs on the version folder as they are not persisted across writes
// Except for the sys.eval.useracl attr as EOS uses that to determine if it needs to obey
// the user ACLs set on the file
if !(attr.Type == eosclient.SystemAttr && attr.Key == userACLEvalKey) {
info, err = c.getRawFileInfoByPath(ctx, auth, path)
if err != nil {
return err
}
if !info.IsDir {
path = getVersionFolder(path)
}
}

// Favorites need to be stored per user so handle these separately
if attr.Type == eosclient.UserAttr && attr.Key == favoritesKey {
return c.handleFavAttr(ctx, auth, attr, recursive, path, info, true)
}
return c.setEOSAttr(ctx, auth, attr, errorIfExists, recursive, path)
Expand Down Expand Up @@ -525,13 +546,23 @@ func (c *Client) UnsetAttr(ctx context.Context, auth eosclient.Authorization, at
return errors.New("eos: attr is invalid: " + serializeAttribute(attr))
}

var info *eosclient.FileInfo
var err error
// Favorites need to be stored per user so handle these separately
if attr.Type == eosclient.UserAttr && attr.Key == favoritesKey {
info, err := c.getRawFileInfoByPath(ctx, auth, path)
// We need to set the attrs on the version folder as they are not persisted across writes
// Except for the sys.eval.useracl attr as EOS uses that to determine if it needs to obey
// the user ACLs set on the file
if !(attr.Type == eosclient.SystemAttr && attr.Key == userACLEvalKey) {
info, err = c.getRawFileInfoByPath(ctx, auth, path)
if err != nil {
return err
}
if !info.IsDir {
path = getVersionFolder(path)
}
}

// Favorites need to be stored per user so handle these separately
if attr.Type == eosclient.UserAttr && attr.Key == favoritesKey {
return c.handleFavAttr(ctx, auth, attr, recursive, path, info, false)
}

Expand All @@ -554,12 +585,21 @@ func (c *Client) UnsetAttr(ctx context.Context, auth eosclient.Authorization, at

// GetAttr returns the attribute specified by key.
func (c *Client) GetAttr(ctx context.Context, auth eosclient.Authorization, key, path string) (*eosclient.Attribute, error) {
// As SetAttr set the attr on the version folder, we will read the attribute on it
// if the resource is not a folder
info, err := c.getRawFileInfoByPath(ctx, auth, path)
if err != nil {
return nil, err
}
if !info.IsDir {
path = getVersionFolder(path)
}

args := []string{"attr", "get", key, path}
attrOut, _, err := c.executeEOS(ctx, args, auth)
if err != nil {
return nil, err
}

attr, err := deserializeAttribute(attrOut)
if err != nil {
return nil, err
Expand All @@ -569,6 +609,14 @@ func (c *Client) GetAttr(ctx context.Context, auth eosclient.Authorization, key,

// GetAttrs returns all the attributes of a resource.
func (c *Client) GetAttrs(ctx context.Context, auth eosclient.Authorization, path string) ([]*eosclient.Attribute, error) {
info, err := c.getRawFileInfoByPath(ctx, auth, path)
if err != nil {
return nil, err
}
if !info.IsDir {
path = getVersionFolder(path)
}

args := []string{"attr", "ls", path}
attrOut, _, err := c.executeEOS(ctx, args, auth)
if err != nil {
Expand Down

0 comments on commit 8d46b0e

Please sign in to comment.