From fe7eeb42432a719b4f47f943c462fda9f9655698 Mon Sep 17 00:00:00 2001 From: Gianmaria Del Monte <39946305+gmgigi96@users.noreply.github.com> Date: Tue, 11 Apr 2023 13:49:04 +0200 Subject: [PATCH] Fix listing directory for a read-only shares for EOS storage driver (#3786) --- .../fix-create-version-folder-on-list-eos.md | 9 +++++++++ pkg/eosclient/eosbinary/eosbinary.go | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 changelog/unreleased/fix-create-version-folder-on-list-eos.md diff --git a/changelog/unreleased/fix-create-version-folder-on-list-eos.md b/changelog/unreleased/fix-create-version-folder-on-list-eos.md new file mode 100644 index 00000000000..c6825a7dac4 --- /dev/null +++ b/changelog/unreleased/fix-create-version-folder-on-list-eos.md @@ -0,0 +1,9 @@ +Bugfix: Fix listing directory for a read-only shares for EOS storage driver + +In a read-only share, while listing a folder, for resources +not having a version folder, the returned resource id was wrongly +the one of the original file, instead of the version folder. +This behavior has been fixed, where the version folder is always +created on behalf of the resource owner. + +https://github.com/cs3org/reva/pull/3786 diff --git a/pkg/eosclient/eosbinary/eosbinary.go b/pkg/eosclient/eosbinary/eosbinary.go index 0e695e22c13..9fc54d6ba76 100644 --- a/pkg/eosclient/eosbinary/eosbinary.go +++ b/pkg/eosclient/eosbinary/eosbinary.go @@ -947,12 +947,16 @@ func getMap(partsBySpace []string) map[string]string { } func (c *Client) parseFind(ctx context.Context, auth eosclient.Authorization, dirPath, raw string) ([]*eosclient.FileInfo, error) { + log := appctx.GetLogger(ctx) + finfos := []*eosclient.FileInfo{} versionFolders := map[string]*eosclient.FileInfo{} rawLines := strings.FieldsFunc(raw, func(c rune) bool { return c == '\n' }) + var ownerAuth *eosclient.Authorization + var parent *eosclient.FileInfo for _, rl := range rawLines { if rl == "" { @@ -976,6 +980,15 @@ func (c *Client) parseFind(ctx context.Context, auth eosclient.Authorization, di versionFolders[fi.File] = fi } + if ownerAuth == nil { + ownerAuth = &eosclient.Authorization{ + Role: eosclient.Role{ + UID: strconv.FormatUint(fi.UID, 10), + GID: strconv.FormatUint(fi.GID, 10), + }, + } + } + finfos = append(finfos, fi) } @@ -993,9 +1006,11 @@ func (c *Client) parseFind(ctx context.Context, auth eosclient.Authorization, di for k, v := range vf.Attrs { fi.Attrs[k] = v } - } else if err := c.CreateDir(ctx, auth, versionFolderPath); err == nil { // Create the version folder if it doesn't exist + } else if err := c.CreateDir(ctx, *ownerAuth, versionFolderPath); err == nil { // Create the version folder if it doesn't exist if md, err := c.getRawFileInfoByPath(ctx, auth, versionFolderPath); err == nil { fi.Inode = md.Inode + } else { + log.Error().Err(err).Interface("auth", ownerAuth).Str("path", versionFolderPath).Msg("got error creating version folder") } } }