Skip to content

Commit

Permalink
fuse: automatically add ro option if mount with --read-only (#1661)
Browse files Browse the repository at this point in the history
  • Loading branch information
SandyXSD committed Mar 28, 2022
1 parent a093860 commit 6f4200f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 20 deletions.
3 changes: 1 addition & 2 deletions cmd/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 2 additions & 11 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 1 addition & 7 deletions cmd/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions pkg/fuse/fuse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
9 changes: 9 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 6f4200f

Please sign in to comment.