Skip to content

Commit

Permalink
Return the inode of the version folder for files when listing in EOS (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 authored Nov 17, 2021
1 parent 2b436a9 commit 99aad0b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
3 changes: 3 additions & 0 deletions changelog/unreleased/eos-list-file-version-inode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Bugfix: Return the inode of the version folder for files when listing in EOS

https://github.com/cs3org/reva/pull/2279
26 changes: 22 additions & 4 deletions pkg/eosclient/eosbinary/eosbinary.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ func (c *Client) List(ctx context.Context, auth eosclient.Authorization, path st
if err != nil {
return nil, errors.Wrapf(err, "eosclient: error listing fn=%s", path)
}
return c.parseFind(path, stdout)
return c.parseFind(ctx, auth, path, stdout)
}

// Read reads a file from the mgm
Expand Down Expand Up @@ -871,8 +871,9 @@ func getMap(partsBySpace []string) map[string]string {
return kv
}

func (c *Client) parseFind(dirPath, raw string) ([]*eosclient.FileInfo, error) {
func (c *Client) parseFind(ctx context.Context, auth eosclient.Authorization, dirPath, raw string) ([]*eosclient.FileInfo, error) {
finfos := []*eosclient.FileInfo{}
versionFolders := map[string]*eosclient.FileInfo{}
rawLines := strings.FieldsFunc(raw, func(c rune) bool {
return c == '\n'
})
Expand All @@ -894,13 +895,30 @@ func (c *Client) parseFind(dirPath, raw string) ([]*eosclient.FileInfo, error) {
continue
}

// If it's a version folder, store it in a map, so that for the corresponding file,
// we can return its inode instead
if isVersionFolder(fi.File) {
versionFolders[fi.File] = fi
}

finfos = append(finfos, fi)
}

for _, fi := range finfos {
// For files, inherit ACLs from the parent
if !fi.IsDir && parent != nil {
fi.SysACL.Entries = append(fi.SysACL.Entries, parent.SysACL.Entries...)
// And set the inode to that of their version folder
if !fi.IsDir {
if parent != nil {
fi.SysACL.Entries = append(fi.SysACL.Entries, parent.SysACL.Entries...)
}
versionFolderPath := getVersionFolder(fi.File)
if vf, ok := versionFolders[versionFolderPath]; ok {
fi.Inode = vf.Inode
} else if err := c.CreateDir(ctx, auth, versionFolderPath); err == nil {
if md, err := c.GetFileInfoByPath(ctx, auth, versionFolderPath); err == nil {
fi.Inode = md.Inode
}
}
}
}

Expand Down

0 comments on commit 99aad0b

Please sign in to comment.