Skip to content

Commit

Permalink
pkg/gateway: Support specifying umask for directories (#2445)
Browse files Browse the repository at this point in the history
* Use the same umask for files and directories
  • Loading branch information
dugusword authored Aug 10, 2022
1 parent bfbab57 commit eba3200
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
13 changes: 11 additions & 2 deletions cmd/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func cmdGateway() *cli.Command {
&cli.StringFlag{
Name: "umask",
Value: "022",
Usage: "umask for new file in octal",
Usage: "umask for new files and directories in octal",
},
}

Expand Down Expand Up @@ -169,7 +169,16 @@ func (g *GateWay) NewGatewayLayer(creds auth.Credentials) (minio.ObjectLayer, er
logger.Fatalf("invalid umask %s: %s", c.String("umask"), err)
}

return jfsgateway.NewJFSGateway(jfs, conf, &jfsgateway.Config{MultiBucket: c.Bool("multi-buckets"), KeepEtag: c.Bool("keep-etag"), Mode: uint16(0777 &^ umask)})
return jfsgateway.NewJFSGateway(
jfs,
conf,
&jfsgateway.Config{
MultiBucket: c.Bool("multi-buckets"),
KeepEtag: c.Bool("keep-etag"),
Mode: uint16(0666 &^ umask),
DirMode: uint16(0777 &^ umask),
},
)
}

func initForSvc(c *cli.Context, mp string, metaUrl string) (*vfs.Config, *fs.FileSystem) {
Expand Down
19 changes: 10 additions & 9 deletions pkg/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Config struct {
MultiBucket bool
KeepEtag bool
Mode uint16
DirMode uint16
}

func NewJFSGateway(jfs *fs.FileSystem, conf *vfs.Config, gConf *Config) (minio.ObjectLayer, error) {
Expand Down Expand Up @@ -190,7 +191,7 @@ func (n *jfsObjects) MakeBucketWithLocation(ctx context.Context, bucket string,
if !n.gConf.MultiBucket {
return nil
}
eno := n.fs.Mkdir(mctx, n.path(bucket), 0755)
eno := n.fs.Mkdir(mctx, n.path(bucket), n.gConf.DirMode)
return jfsToObjectErr(ctx, eno, bucket)
}

Expand Down Expand Up @@ -448,8 +449,8 @@ func (n *jfsObjects) CopyObject(ctx context.Context, srcBucket, srcObject, dstBu
return n.GetObjectInfo(ctx, srcBucket, srcObject, minio.ObjectOptions{})
}
tmp := n.tpath(dstBucket, "tmp", minio.MustGetUUID())
_ = n.mkdirAll(ctx, path.Dir(tmp), 0755)
_, eno := n.fs.Create(mctx, tmp, 0644)
_ = n.mkdirAll(ctx, path.Dir(tmp), os.FileMode(n.gConf.DirMode))
_, eno := n.fs.Create(mctx, tmp, n.gConf.Mode)
if eno != 0 {
logger.Errorf("create %s: %s", tmp, eno)
return
Expand Down Expand Up @@ -572,7 +573,7 @@ func (n *jfsObjects) mkdirAll(ctx context.Context, p string, mode os.FileMode) e
}
eno := n.fs.Mkdir(mctx, p, uint16(mode))
if eno != 0 && fs.IsNotExist(eno) {
if err := n.mkdirAll(ctx, path.Dir(p), 0755); err != nil {
if err := n.mkdirAll(ctx, path.Dir(p), os.FileMode(n.gConf.DirMode)); err != nil {
return err
}
eno = n.fs.Mkdir(mctx, p, uint16(mode))
Expand All @@ -588,7 +589,7 @@ func (n *jfsObjects) mkdirAll(ctx context.Context, p string, mode os.FileMode) e

func (n *jfsObjects) putObject(ctx context.Context, bucket, object string, r *minio.PutObjReader, opts minio.ObjectOptions) (err error) {
tmpname := n.tpath(bucket, "tmp", minio.MustGetUUID())
_ = n.mkdirAll(ctx, path.Dir(tmpname), 0755)
_ = n.mkdirAll(ctx, path.Dir(tmpname), os.FileMode(n.gConf.DirMode))
f, eno := n.fs.Create(mctx, tmpname, n.gConf.Mode)
if eno != 0 {
logger.Errorf("create %s: %s", tmpname, eno)
Expand Down Expand Up @@ -626,7 +627,7 @@ func (n *jfsObjects) putObject(ctx context.Context, bucket, object string, r *mi
}
dir := path.Dir(object)
if dir != "" {
_ = n.mkdirAll(ctx, dir, os.FileMode(0755))
_ = n.mkdirAll(ctx, dir, os.FileMode(n.gConf.DirMode))
}
if eno := n.fs.Rename(mctx, tmpname, object, 0); eno != 0 {
err = jfsToObjectErr(ctx, eno, bucket, object)
Expand All @@ -642,7 +643,7 @@ func (n *jfsObjects) PutObject(ctx context.Context, bucket string, object string

p := n.path(bucket, object)
if strings.HasSuffix(object, sep) {
if err = n.mkdirAll(ctx, p, os.FileMode(0755)); err != nil {
if err = n.mkdirAll(ctx, p, os.FileMode(n.gConf.DirMode)); err != nil {
err = jfsToObjectErr(ctx, err, bucket, object)
return
}
Expand Down Expand Up @@ -685,7 +686,7 @@ func (n *jfsObjects) NewMultipartUpload(ctx context.Context, bucket string, obje
}
uploadID = minio.MustGetUUID()
p := n.upath(bucket, uploadID)
err = n.mkdirAll(ctx, p, os.FileMode(0755))
err = n.mkdirAll(ctx, p, os.FileMode(n.gConf.DirMode))
if err == nil {
eno := n.fs.SetXattr(mctx, p, uploadKeyName, []byte(object), 0)
if eno != 0 {
Expand Down Expand Up @@ -861,7 +862,7 @@ func (n *jfsObjects) CompleteMultipartUpload(ctx context.Context, bucket, object
name := n.path(bucket, object)
dir := path.Dir(name)
if dir != "" {
if err = n.mkdirAll(ctx, dir, os.FileMode(0755)); err != nil {
if err = n.mkdirAll(ctx, dir, os.FileMode(n.gConf.DirMode)); err != nil {
_ = n.fs.Delete(mctx, tmp)
err = jfsToObjectErr(ctx, err, bucket, object, uploadID)
return
Expand Down

0 comments on commit eba3200

Please sign in to comment.