diff --git a/cmd/gateway.go b/cmd/gateway.go index 53be4cd80070..71fade7594d6 100644 --- a/cmd/gateway.go +++ b/cmd/gateway.go @@ -173,8 +173,7 @@ func (g *GateWay) NewGatewayLayer(creds auth.Credentials) (minio.ObjectLayer, er } func initForSvc(c *cli.Context, mp string, metaUrl string) (meta.Meta, chunk.ChunkStore, *vfs.Config) { - readOnly := c.Bool("read-only") - metaConf := getMetaConf(c, mp, readOnly) + metaConf := getMetaConf(c, mp, c.Bool("read-only")) metaCli := meta.NewClient(metaUrl, metaConf) format, err := metaCli.Load(true) if err != nil { diff --git a/cmd/main.go b/cmd/main.go index 5d4140975aed..79612a864e06 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -121,7 +121,7 @@ func handleSysMountArgs(args []string) ([]string, error) { opts := strings.Split(option, ",") for _, opt := range opts { opt = strings.TrimSpace(opt) - if opt == "" || stringContains(sysOptions, opt) { + if opt == "" || utils.StringContains(sysOptions, opt) { continue } // Lower case option name is preferred, but if it's the same as flag name, we also accept it @@ -156,15 +156,6 @@ func handleSysMountArgs(args []string) ([]string, error) { return newArgs, nil } -func stringContains(s []string, e string) bool { - for _, item := range s { - if item == e { - return true - } - } - return false -} - func isFlag(flags []cli.Flag, option string) (bool, bool) { if !strings.HasPrefix(option, "-") { return false, false @@ -227,7 +218,7 @@ func reorderOptions(app *cli.App, args []string) []string { newArgs = append(newArgs, args[i]) } } else { - if strings.HasPrefix(option, "-") && !stringContains(args, "--generate-bash-completion") { + if strings.HasPrefix(option, "-") && !utils.StringContains(args, "--generate-bash-completion") { logger.Fatalf("unknown option: %s", option) } others = append(others, option) diff --git a/cmd/mount.go b/cmd/mount.go index 558c98fc5be0..be19b83bf86c 100644 --- a/cmd/mount.go +++ b/cmd/mount.go @@ -329,13 +329,7 @@ func mount(c *cli.Context) error { mp := c.Args().Get(1) prepareMp(mp) - var readOnly = c.Bool("read-only") - for _, o := range strings.Split(c.String("o"), ",") { - if o == "ro" { - readOnly = true - } - } - metaConf := getMetaConf(c, mp, readOnly) + metaConf := getMetaConf(c, mp, c.Bool("read-only") || utils.StringContains(strings.Split(c.String("o"), ","), "ro")) metaConf.CaseInsensi = strings.HasSuffix(mp, ":") && runtime.GOOS == "windows" metaCli := meta.NewClient(addr, metaConf) format := getFormat(c, metaCli) diff --git a/pkg/fuse/fuse.go b/pkg/fuse/fuse.go index 9958c9004742..186d797dae1f 100644 --- a/pkg/fuse/fuse.go +++ b/pkg/fuse/fuse.go @@ -446,6 +446,9 @@ func Serve(v *vfs.VFS, options string, xattrs bool) error { opt.Options = append(opt.Options, n) } } + if conf.Meta.ReadOnly && !utils.StringContains(opt.Options, "ro") { + opt.Options = append(opt.Options, "ro") + } opt.Options = append(opt.Options, "default_permissions") if runtime.GOOS == "darwin" { opt.Options = append(opt.Options, "fssubtype=juicefs") diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 49e15c9c444e..b9fe77312c00 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -99,3 +99,12 @@ func GuessMimeType(key string) string { } return mimeType } + +func StringContains(s []string, e string) bool { + for _, item := range s { + if item == e { + return true + } + } + return false +}