Skip to content

Commit

Permalink
Allow --ro=[true|false] with mount flag
Browse files Browse the repository at this point in the history
The 'podman run --mount' flag previously allowed the 'ro' option
to be specified, but was missing the ability to set it to a bool
(as is allowed by docker). Add that. While we're at it, allow
setting 'rw' explicitly as well.

Fixes containers#2980

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
  • Loading branch information
mheon committed Aug 6, 2019
1 parent b5618d9 commit fe4f1e9
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion pkg/spec/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,13 +410,42 @@ func getBindMount(args []string) (spec.Mount, error) {

setSource := false
setDest := false
setRORW := false

for _, val := range args {
kv := strings.Split(val, "=")
switch kv[0] {
case "bind-nonrecursive":
newMount.Options = append(newMount.Options, "bind")
case "ro", "nosuid", "nodev", "noexec":
case "ro", "rw":
if setRORW == true {
return newMount, errors.Wrapf(optionArgError, "cannot pass %s more than once", kv[0])
}
setRORW = true
// Can be formatted as one of:
// ro
// ro=[true|false]
// rw
// rw=[true|false]
if len(kv) == 1 {
newMount.Options = append(newMount.Options, kv[0])
} else if len(kv) == 2 {
switch strings.ToLower(kv[1]) {
case "true":
newMount.Options = append(newMount.Options, kv[0])
case "false":
// Set the opposite only for rw
// ro's opposite is the default
if kv[0] == "rw" {
newMount.Options = append(newMount.Options, "ro")
}
default:
return newMount, errors.Wrapf(optionArgError, "%s must be set to true or false, instead got %q", kv[0], kv[1])
}
} else {
return newMount, errors.Wrapf(optionArgError, "badly formatted option %q", val)
}
case "nosuid", "nodev", "noexec":
// TODO: detect duplication of these options.
// (Is this necessary?)
newMount.Options = append(newMount.Options, kv[0])
Expand Down

0 comments on commit fe4f1e9

Please sign in to comment.