From 79038fe2f967ab15a760f6a78fc310d2eea55ef5 Mon Sep 17 00:00:00 2001 From: Fabrizio Furano Date: Tue, 6 Oct 2020 16:05:32 +0200 Subject: [PATCH] Add WriteFile to eosclientgrpc --- pkg/eosclientgrpc/eosclientgrpc.go | 12 ++++++++++-- pkg/storage/fs/eosgrpc/upload.go | 7 ------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/pkg/eosclientgrpc/eosclientgrpc.go b/pkg/eosclientgrpc/eosclientgrpc.go index d7630d6e827..9389d5c3b60 100644 --- a/pkg/eosclientgrpc/eosclientgrpc.go +++ b/pkg/eosclientgrpc/eosclientgrpc.go @@ -28,7 +28,6 @@ import ( "os/exec" gouser "os/user" "path" - "path/filepath" "strconv" "syscall" @@ -38,6 +37,7 @@ import ( "github.com/cs3org/reva/pkg/storage/utils/acl" "github.com/gofrs/uuid" "github.com/pkg/errors" + "github.com/rs/zerolog/log" "google.golang.org/grpc" "github.com/cs3org/reva/pkg/logger" @@ -662,7 +662,7 @@ func (c *Client) GetFileInfoByPath(ctx context.Context, username, path string) ( log.Info().Str("username", username).Str("path", path).Str("rsp:", fmt.Sprintf("%#v", rsp)).Msg("grpc response") - return c.grpcMDResponseToFileInfo(rsp, filepath.Dir(path)) + return c.grpcMDResponseToFileInfo(rsp, "") } @@ -1036,14 +1036,17 @@ func (c *Client) Write(ctx context.Context, username, path string, stream io.Rea // WriteFile writes an existing file to the mgm func (c *Client) WriteFile(ctx context.Context, username, path, source string) error { + unixUser, err := c.getUnixUser(username) if err != nil { return err } + xrdPath := fmt.Sprintf("%s//%s", c.opt.URL, path) cmd := exec.CommandContext(ctx, c.opt.XrdcopyBinary, "--nopbar", "--silent", "-f", source, xrdPath, fmt.Sprintf("-ODeos.ruid=%s&eos.rgid=%s", unixUser.Uid, unixUser.Gid)) _, _, err = c.execute(ctx, cmd) return err + } // ListDeletedEntries returns a list of the deleted entries. @@ -1238,11 +1241,14 @@ func (c *Client) grpcMDResponseToFileInfo(st *erpc.MDResponse, namepfx string) ( fi.File = namepfx + "/" + string(st.Cmd.Name) } + var allattrs = "" for k, v := range st.Cmd.Xattrs { if fi.Attrs == nil { fi.Attrs = make(map[string]string) } fi.Attrs[k] = string(v) + allattrs += string(v) + allattrs += "," } fi.Size = 0 @@ -1250,6 +1256,8 @@ func (c *Client) grpcMDResponseToFileInfo(st *erpc.MDResponse, namepfx string) ( fi.ETag = fi.Attrs["etag"] + log.Debug().Str("stat info - path", fi.File).Uint64("inode:", fi.Inode).Uint64("uid:", fi.UID).Uint64("gid:", fi.GID).Str("etag:", fi.ETag).Msg("grpc response") + return fi, nil } diff --git a/pkg/storage/fs/eosgrpc/upload.go b/pkg/storage/fs/eosgrpc/upload.go index 0e8d0f8214e..847a1bff9c1 100644 --- a/pkg/storage/fs/eosgrpc/upload.go +++ b/pkg/storage/fs/eosgrpc/upload.go @@ -285,13 +285,6 @@ func (upload *fileUpload) FinishUpload(ctx context.Context) error { } np := filepath.Join(upload.info.MetaData["dir"], upload.info.MetaData["filename"]) - // TODO check etag with If-Match header - // if destination exists - //if _, err := os.Stat(np); err == nil { - // copy attributes of existing file to tmp file before overwriting the target? - // eos creates revisions internally - //} - err := upload.fs.c.WriteFile(ctx, upload.info.Storage["Username"], np, upload.binPath) // only delete the upload if it was successfully written to eos