Skip to content

Commit

Permalink
Add WriteFile to eosclientgrpc
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabrizio Furano committed Oct 6, 2020
1 parent 35f781b commit 01b2ae2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
12 changes: 10 additions & 2 deletions pkg/eosclientgrpc/eosclientgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"os/exec"
gouser "os/user"
"path"
"path/filepath"
"strconv"
"syscall"

Expand All @@ -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"
Expand Down Expand Up @@ -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, "")

}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -1238,18 +1241,23 @@ 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
}

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
}

Expand Down
7 changes: 0 additions & 7 deletions pkg/storage/fs/eosgrpc/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 01b2ae2

Please sign in to comment.