Skip to content

Commit

Permalink
Fix Stat() for eos storage provider (#2074)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmgigi96 authored Sep 16, 2021
1 parent 3cb3c21 commit 3eac14a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
8 changes: 8 additions & 0 deletions changelog/unreleased/stat-eos.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Bugfix: Fix Stat() for EOS storage provider

This change fixes the convertion between the eosclient.FileInfo
to ResourceInfo, in which the field ArbitraryMetadata was missing.
Moreover, to be consistent with SetArbitraryMetadata() EOS implementation,
all the "user." prefix are stripped out from the xattrs.

https://github.com/cs3org/reva/pull/2074
15 changes: 8 additions & 7 deletions pkg/eosclient/eosbinary/eosbinary.go
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,7 @@ func (c *Client) parseFileInfo(raw string) (*eosclient.FileInfo, error) {
name := line[0:length]

kv := make(map[string]string)
attrs := make(map[string]string)
// strip trailing slash
kv["file"] = strings.TrimSuffix(name, "/")

Expand All @@ -948,17 +949,17 @@ func (c *Client) parseFileInfo(raw string) (*eosclient.FileInfo, error) {
// handle xattrn and xattrv special cases
switch {
case partsByEqual[0] == "xattrn":
previousXAttr = partsByEqual[1]
previousXAttr = strings.Replace(partsByEqual[1], "user.", "", 1)
case partsByEqual[0] == "xattrv":
kv[previousXAttr] = partsByEqual[1]
attrs[previousXAttr] = partsByEqual[1]
previousXAttr = ""
default:
kv[partsByEqual[0]] = partsByEqual[1]

}
}
}
fi, err := c.mapToFileInfo(kv)
fi, err := c.mapToFileInfo(kv, attrs)
if err != nil {
return nil, err
}
Expand All @@ -968,7 +969,7 @@ func (c *Client) parseFileInfo(raw string) (*eosclient.FileInfo, error) {
// mapToFileInfo converts the dictionary to an usable structure.
// The kv has format:
// map[sys.forced.space:default files:0 mode:42555 ino:5 sys.forced.blocksize:4k sys.forced.layout:replica uid:0 fid:5 sys.forced.blockchecksum:crc32c sys.recycle:/eos/backup/proc/recycle/ fxid:00000005 pid:1 etag:5:0.000 keylength.file:4 file:/eos treesize:1931593933849913 container:3 gid:0 mtime:1498571294.108614409 ctime:1460121992.294326762 pxid:00000001 sys.forced.checksum:adler sys.forced.nstripes:2]
func (c *Client) mapToFileInfo(kv map[string]string) (*eosclient.FileInfo, error) {
func (c *Client) mapToFileInfo(kv, attrs map[string]string) (*eosclient.FileInfo, error) {
inode, err := strconv.ParseUint(kv["ino"], 10, 64)
if err != nil {
return nil, err
Expand Down Expand Up @@ -1055,11 +1056,11 @@ func (c *Client) mapToFileInfo(kv map[string]string) (*eosclient.FileInfo, error
}
}

sysACL, err := acl.Parse(kv["sys.acl"], acl.ShortTextForm)
sysACL, err := acl.Parse(attrs["sys.acl"], acl.ShortTextForm)
if err != nil {
return nil, err
}
lwACLStr, ok := kv[lwShareAttrKey]
lwACLStr, ok := attrs[lwShareAttrKey]
if ok {
lwAcls, err := acl.Parse(lwACLStr, acl.ShortTextForm)
if err != nil {
Expand Down Expand Up @@ -1088,7 +1089,7 @@ func (c *Client) mapToFileInfo(kv map[string]string) (*eosclient.FileInfo, error
Instance: c.opt.URL,
SysACL: sysACL,
TreeCount: treeCount,
Attrs: kv,
Attrs: attrs,
XS: xs,
}

Expand Down
11 changes: 11 additions & 0 deletions pkg/storage/utils/eosfs/eosfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,14 @@ func (fs *eosfs) convert(ctx context.Context, eosFileInfo *eosclient.FileInfo) (
}
}

// filter 'sys' attrs
filteredAttrs := make(map[string]string)
for k, v := range eosFileInfo.Attrs {
if !strings.HasPrefix(k, "sys") {
filteredAttrs[k] = v
}
}

info := &provider.ResourceInfo{
Id: &provider.ResourceId{OpaqueId: fmt.Sprintf("%d", eosFileInfo.Inode)},
Path: path,
Expand All @@ -1697,6 +1705,9 @@ func (fs *eosfs) convert(ctx context.Context, eosFileInfo *eosclient.FileInfo) (
},
},
},
ArbitraryMetadata: &provider.ArbitraryMetadata{
Metadata: filteredAttrs,
},
}

if eosFileInfo.IsDir {
Expand Down

0 comments on commit 3eac14a

Please sign in to comment.