@@ -23,6 +23,7 @@ import (
23
23
"context"
24
24
"fmt"
25
25
"io"
26
+ "io/ioutil"
26
27
"os"
27
28
"os/exec"
28
29
"path"
@@ -37,13 +38,13 @@ import (
37
38
//erpc "github.com/cs3org/reva/pkg/eosclient/eosgrpc/eos_grpc"
38
39
ehttp "github.com/cs3org/reva/pkg/eosclient/eosgrpc/eos_http"
39
40
"github.com/cs3org/reva/pkg/errtypes"
41
+ "github.com/cs3org/reva/pkg/logger"
40
42
"github.com/cs3org/reva/pkg/storage/utils/acl"
41
43
erpc "github.com/ffurano/grpc-proto/protobuf"
44
+ "github.com/google/uuid"
42
45
"github.com/pkg/errors"
43
46
"github.com/rs/zerolog/log"
44
47
"google.golang.org/grpc"
45
-
46
- "github.com/cs3org/reva/pkg/logger"
47
48
)
48
49
49
50
const (
@@ -82,6 +83,14 @@ type Options struct {
82
83
// Defaults to os.TempDir()
83
84
CacheDirectory string
84
85
86
+ // Set to true to use the local disk as a buffer for chunk
87
+ // reads from EOS. Default is false, i.e. pure streaming
88
+ ReadUsesLocalTemp bool
89
+
90
+ // Set to true to use the local disk as a buffer for chunk
91
+ // writes to EOS. Default is false, i.e. pure streaming
92
+ WriteUsesLocalTemp bool
93
+
85
94
// Keytab is the location of the EOS keytab file.
86
95
Keytab string
87
96
@@ -655,7 +664,7 @@ func (c *Client) GetQuota(ctx context.Context, username, rootUID, rootGID, path
655
664
msg := new (erpc.NSRequest_QuotaRequest )
656
665
msg .Path = []byte (path )
657
666
msg .Id = new (erpc.RoleId )
658
-
667
+ msg . Op = erpc . QUOTAOP_GET
659
668
// Eos filters the returned quotas by username. This means that EOS must know it, someone
660
669
// must have created an user with that name
661
670
msg .Id .Username = username
@@ -737,13 +746,14 @@ func (c *Client) SetQuota(ctx context.Context, rootUID, rootGID string, info *eo
737
746
if err != nil {
738
747
return err
739
748
}
740
- gidInt , err := strconv .ParseUint (info .GID , 10 , 64 )
741
- if err != nil {
742
- return err
743
- }
749
+
750
+ // We set a quota for an user, not a group!
744
751
msg .Id .Uid = uidInt
745
- msg .Id .Gid = gidInt
752
+ msg .Id .Gid = 0
746
753
msg .Id .Username = info .Username
754
+ msg .Op = erpc .QUOTAOP_SET
755
+ msg .Maxbytes = info .MaxBytes
756
+ msg .Maxfiles = info .MaxFiles
747
757
rq .Command = & erpc.NSRequest_Quota {Quota : msg }
748
758
749
759
// Now send the req and see what happens
@@ -1161,20 +1171,22 @@ func (c *Client) Read(ctx context.Context, uid, gid, path string) (io.ReadCloser
1161
1171
log .Info ().Str ("func" , "Read" ).Str ("uid,gid" , uid + "," + gid ).Str ("path" , path ).Msg ("" )
1162
1172
1163
1173
var localTarget string
1164
- //rand := "eosread-" + uuid.New().String()
1165
- //localTarget := fmt.Sprintf("%s/%s", c.opt.CacheDirectory, rand)
1166
- //defer os.RemoveAll(localTarget)
1167
-
1174
+ var err error
1168
1175
var localfile io.WriteCloser
1169
1176
localfile = nil
1170
1177
1171
- // Uncomment to create a local temp file. Otherwise it streams. With the streaming
1172
- // it's more difficult to return a sound error in the case of troubles
1173
- // localfile, err := os.Create(localTarget)
1174
- // if err != nil {
1175
- // log.Error().Str("func", "Read").Str("path", path).Str("uid,gid", uid+","+gid).Str("err", err.Error()).Msg("")
1176
- // return nil, errtypes.InternalError(fmt.Sprintf("can't open local cache file '%s'", localTarget))
1177
- // }
1178
+ if c .opt .ReadUsesLocalTemp {
1179
+ rand := "eosread-" + uuid .New ().String ()
1180
+ localTarget := fmt .Sprintf ("%s/%s" , c .opt .CacheDirectory , rand )
1181
+ defer os .RemoveAll (localTarget )
1182
+
1183
+ log .Info ().Str ("func" , "Read" ).Str ("uid,gid" , uid + "," + gid ).Str ("path" , path ).Str ("tempfile" , localTarget ).Msg ("" )
1184
+ localfile , err = os .Create (localTarget )
1185
+ if err != nil {
1186
+ log .Error ().Str ("func" , "Read" ).Str ("path" , path ).Str ("uid,gid" , uid + "," + gid ).Str ("err" , err .Error ()).Msg ("" )
1187
+ return nil , errtypes .InternalError (fmt .Sprintf ("can't open local temp file '%s'" , localTarget ))
1188
+ }
1189
+ }
1178
1190
1179
1191
err , bodystream := c .GetHTTPCl ().GETFile (ctx , "" , uid , gid , path , localfile )
1180
1192
if err != nil {
@@ -1192,18 +1204,30 @@ func (c *Client) Write(ctx context.Context, uid, gid, path string, stream io.Rea
1192
1204
log := appctx .GetLogger (ctx )
1193
1205
log .Info ().Str ("func" , "Write" ).Str ("uid,gid" , uid + "," + gid ).Str ("path" , path ).Msg ("" )
1194
1206
1195
- //fd, err := ioutil.TempFile(c.opt.CacheDirectory, "eoswrite-")
1196
- //if err != nil {
1197
- // return err
1198
- // }
1199
- // defer fd.Close()
1200
- // defer os.RemoveAll(fd.Name())
1201
- //
1202
- // // copy stream to local temp file
1203
- // _, err = io.Copy(fd, stream)
1204
- // if err != nil {
1205
- //return err
1206
- //}
1207
+ if c .opt .ReadUsesLocalTemp {
1208
+ fd , err := ioutil .TempFile (c .opt .CacheDirectory , "eoswrite-" )
1209
+ if err != nil {
1210
+ return err
1211
+ }
1212
+ defer fd .Close ()
1213
+ defer os .RemoveAll (fd .Name ())
1214
+
1215
+ log .Info ().Str ("func" , "Write" ).Str ("uid,gid" , uid + "," + gid ).Str ("path" , path ).Str ("tempfile" , fd .Name ()).Msg ("" )
1216
+ // copy stream to local temp file
1217
+ _ , err = io .Copy (fd , stream )
1218
+ if err != nil {
1219
+ return err
1220
+ }
1221
+
1222
+ wfd , err := os .Open (fd .Name ())
1223
+ defer wfd .Close ()
1224
+ defer os .RemoveAll (fd .Name ())
1225
+ if err != nil {
1226
+ return err
1227
+ }
1228
+
1229
+ return c .GetHTTPCl ().PUTFile (ctx , "" , uid , gid , path , wfd )
1230
+ }
1207
1231
1208
1232
return c .GetHTTPCl ().PUTFile (ctx , "" , uid , gid , path , stream )
1209
1233
0 commit comments