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

Return the inode of the version folder for files when listing in EOS #2279

Merged
merged 2 commits into from
Nov 17, 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
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