Skip to content

Commit

Permalink
Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Oct 14, 2021
1 parent 1ddf1a0 commit ed5a9f6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 35 deletions.
29 changes: 7 additions & 22 deletions pkg/eosclient/eosbinary/eosbinary.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,16 +462,7 @@ func (c *Client) GetFileInfoByInode(ctx context.Context, auth eosclient.Authoriz
info.Inode = inode
}

// We need to inherit the ACLs for the parent directory as these are not available for files
if !info.IsDir {
parentInfo, err := c.GetFileInfoByPath(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...)
}
}

return info, nil
return c.mergeParentACLsForFiles(ctx, auth, info), nil
}

// GetFileInfoByFXID returns the FileInfo by the given file id in hexadecimal
Expand All @@ -487,16 +478,7 @@ func (c *Client) GetFileInfoByFXID(ctx context.Context, auth eosclient.Authoriza
return nil, err
}

// We need to inherit the ACLs for the parent directory as these are not available for files
if !info.IsDir {
parentInfo, err := c.GetFileInfoByPath(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...)
}
}

return info, nil
return c.mergeParentACLsForFiles(ctx, auth, info), nil
}

// GetFileInfoByPath returns the FilInfo at the given path
Expand All @@ -517,6 +499,10 @@ func (c *Client) GetFileInfoByPath(ctx context.Context, auth eosclient.Authoriza
}
}

return c.mergeParentACLsForFiles(ctx, auth, info), nil
}

func (c *Client) mergeParentACLsForFiles(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
if !info.IsDir {
parentInfo, err := c.GetFileInfoByPath(ctx, auth, path.Dir(info.File))
Expand All @@ -525,8 +511,7 @@ func (c *Client) GetFileInfoByPath(ctx context.Context, auth eosclient.Authoriza
info.SysACL.Entries = append(info.SysACL.Entries, parentInfo.SysACL.Entries...)
}
}

return info, nil
return info
}

// SetAttr sets an extended attributes on a path.
Expand Down
20 changes: 7 additions & 13 deletions pkg/eosclient/eosgrpc/eosgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,11 @@ func (c *Client) GetFileInfoByInode(ctx context.Context, auth eosclient.Authoriz
info.Inode = inode
}

log.Debug().Str("func", "GetFileInfoByInode").Uint64("inode", inode).Msg("")
return c.mergeParentACLsForFiles(ctx, auth, info), nil
}

func (c *Client) mergeParentACLsForFiles(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
if !info.IsDir {
parentInfo, err := c.GetFileInfoByPath(ctx, auth, path.Dir(info.File))
Expand All @@ -492,9 +497,7 @@ func (c *Client) GetFileInfoByInode(ctx context.Context, auth eosclient.Authoriz
info.SysACL.Entries = append(info.SysACL.Entries, parentInfo.SysACL.Entries...)
}
}

log.Debug().Str("func", "GetFileInfoByInode").Uint64("inode", inode).Msg("")
return info, nil
return info
}

// SetAttr sets an extended attributes on a path.
Expand Down Expand Up @@ -637,16 +640,7 @@ func (c *Client) GetFileInfoByPath(ctx context.Context, auth eosclient.Authoriza
info.Inode = inode
}

// We need to inherit the ACLs for the parent directory as these are not available for files
if !info.IsDir {
parentInfo, err := c.GetFileInfoByPath(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...)
}
}

return info, nil
return c.mergeParentACLsForFiles(ctx, auth, info), nil
}

// GetFileInfoByFXID returns the FileInfo by the given file id in hexadecimal
Expand Down

0 comments on commit ed5a9f6

Please sign in to comment.