From 7d64d6e4741da96b538d661fcb2af9e48fa99c2b Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Fri, 9 Apr 2021 09:11:56 +0200 Subject: [PATCH] eos: fixes for enabling file sharing (#1619) --- changelog/unreleased/eos-file-sharing.md | 3 + pkg/eosclient/eosbinary/eosbinary.go | 93 ++++++++---------------- 2 files changed, 33 insertions(+), 63 deletions(-) create mode 100644 changelog/unreleased/eos-file-sharing.md diff --git a/changelog/unreleased/eos-file-sharing.md b/changelog/unreleased/eos-file-sharing.md new file mode 100644 index 00000000000..759d8400dbe --- /dev/null +++ b/changelog/unreleased/eos-file-sharing.md @@ -0,0 +1,3 @@ +Bugfix: Fixes for enabling file sharing in EOS + +https://github.com/cs3org/reva/pull/1619 diff --git a/pkg/eosclient/eosbinary/eosbinary.go b/pkg/eosclient/eosbinary/eosbinary.go index 17679a21f9c..bb22ce5bcfe 100644 --- a/pkg/eosclient/eosbinary/eosbinary.go +++ b/pkg/eosclient/eosbinary/eosbinary.go @@ -27,6 +27,7 @@ import ( "os" "os/exec" "path" + "path/filepath" "strconv" "strings" "syscall" @@ -40,13 +41,8 @@ import ( "go.opencensus.io/trace" ) -type eosVersion string - const ( versionPrefix = ".sys.v#." - - versionAquamarine = eosVersion("aquamarine") - versionCitrine = eosVersion("citrine") ) const ( @@ -262,59 +258,31 @@ func (c *Client) executeEOS(ctx context.Context, cmd *exec.Cmd) (string, string, return outBuf.String(), errBuf.String(), err } -func (c *Client) getVersion(ctx context.Context, rootUID, rootGID string) (eosVersion, error) { - cmd := exec.CommandContext(ctx, c.opt.EosBinary, "-r", rootUID, rootGID, "version") - stdout, _, err := c.executeEOS(ctx, cmd) - if err != nil { - return "", err - } - return c.parseVersion(ctx, stdout), nil -} - -func (c *Client) parseVersion(ctx context.Context, raw string) eosVersion { - var serverVersion string - rawLines := strings.Split(raw, "\n") - for _, rl := range rawLines { - if rl == "" { - continue - } - if strings.HasPrefix(rl, "EOS_SERVER_VERSION") { - serverVersion = strings.Split(strings.Split(rl, " ")[0], "=")[1] - break - } - } - - if strings.HasPrefix(serverVersion, "4.") { - return versionCitrine - } - return versionAquamarine -} - // AddACL adds an new acl to EOS with the given aclType. func (c *Client) AddACL(ctx context.Context, uid, gid, rootUID, rootGID, path string, a *acl.Entry) error { - version, err := c.getVersion(ctx, rootUID, rootGID) + finfo, err := c.GetFileInfoByPath(ctx, uid, gid, path) if err != nil { return err } + sysACL := a.CitrineSerialize() + args := []string{"-r", rootUID, rootGID, "acl"} - var cmd *exec.Cmd - if version == versionCitrine { - sysACL := a.CitrineSerialize() - cmd = exec.CommandContext(ctx, c.opt.EosBinary, "-r", rootUID, rootGID, "acl", "--sys", "--recursive", sysACL, path) + if finfo.IsDir { + args = append(args, "--sys", "--recursive") } else { - acls, err := c.getACLForPath(ctx, uid, gid, path) - if err != nil { - return err + args = append(args, "--user") + userACLAttr := &eosclient.Attribute{ + Type: SystemAttr, + Key: "eval.useracl", + Val: "1", } - - err = acls.SetEntry(a.Type, a.Qualifier, a.Permissions) - if err != nil { + if err = c.SetAttr(ctx, uid, gid, userACLAttr, false, path); err != nil { return err } - sysACL := acls.Serialize() - cmd = exec.CommandContext(ctx, c.opt.EosBinary, "-r", rootUID, rootGID, "attr", "-r", "set", fmt.Sprintf("sys.acl=%s", sysACL), path) } + args = append(args, sysACL, path) + cmd := exec.CommandContext(ctx, c.opt.EosBinary, args...) _, _, err = c.executeEOS(ctx, cmd) return err @@ -322,29 +290,30 @@ func (c *Client) AddACL(ctx context.Context, uid, gid, rootUID, rootGID, path st // RemoveACL removes the acl from EOS. func (c *Client) RemoveACL(ctx context.Context, uid, gid, rootUID, rootGID, path string, a *acl.Entry) error { - version, err := c.getVersion(ctx, rootUID, rootGID) + finfo, err := c.GetFileInfoByPath(ctx, uid, gid, path) if err != nil { return err } - var cmd *exec.Cmd - if version == versionCitrine { - sysACL := a.CitrineSerialize() - cmd = exec.CommandContext(ctx, c.opt.EosBinary, "-r", rootUID, rootGID, "acl", "--sys", "--recursive", sysACL, path) + sysACL := a.CitrineSerialize() + args := []string{"-r", rootUID, rootGID, "acl"} + if finfo.IsDir { + args = append(args, "--sys", "--recursive") } else { - acls, err := c.getACLForPath(ctx, uid, gid, path) - if err != nil { + args = append(args, "--user") + userACLAttr := &eosclient.Attribute{ + Type: SystemAttr, + Key: "eval.useracl", + } + if err = c.UnsetAttr(ctx, uid, gid, userACLAttr, path); err != nil { return err } - - acls.DeleteEntry(a.Type, a.Qualifier) - sysACL := acls.Serialize() - cmd = exec.CommandContext(ctx, c.opt.EosBinary, "-r", rootUID, rootGID, "attr", "-r", "set", fmt.Sprintf("sys.acl=%s", sysACL), path) } + args = append(args, sysACL, path) + cmd := exec.CommandContext(ctx, c.opt.EosBinary, args...) _, _, err = c.executeEOS(ctx, cmd) return err - } // UpdateACL updates the EOS acl. @@ -437,11 +406,9 @@ func (c *Client) GetFileInfoByPath(ctx context.Context, uid, gid, path string) ( } if c.opt.VersionInvariant && !isVersionFolder(path) && !info.IsDir { - inode, err := c.getVersionFolderInode(ctx, uid, gid, path) - if err != nil { - return nil, err + if inode, err := c.getVersionFolderInode(ctx, uid, gid, path); err == nil { + info.Inode = inode } - info.Inode = inode } return info, nil @@ -791,7 +758,7 @@ func (c *Client) parseQuota(path, raw string) (*eosclient.QuotaInfo, error) { // map[maxbytes:2000000000000 maxlogicalbytes:1000000000000 percentageusedbytes:0.49 quota:node uid:gonzalhu space:/eos/scratch/user/ usedbytes:9829986500 usedlogicalbytes:4914993250 statusfiles:ok usedfiles:334 maxfiles:1000000 statusbytes:ok] space := m["space"] - if strings.HasPrefix(path, space) { + if strings.HasPrefix(path, filepath.Clean(space)) { maxBytesString := m["maxlogicalbytes"] usedBytesString := m["usedlogicalbytes"] maxBytes, _ := strconv.ParseUint(maxBytesString, 10, 64)