зеркало из https://github.com/microsoft/docker.git
Change return value for ValidateMountMode
1. rename it from ValidateMountMode to ValidMountMode Because it's a function simply check mount mode is valid or not. 2. remove the rw check return value It's not supposed to be combined into this function, and we already have a function for that check. Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
This commit is contained in:
Родитель
7ead74d903
Коммит
c99ed5ae5d
|
@ -71,11 +71,10 @@ func parseBindMount(spec string, mountLabel string, config *runconfig.Config) (*
|
|||
case 3:
|
||||
bind.Destination = arr[1]
|
||||
mode := arr[2]
|
||||
isValid, isRw := volume.ValidateMountMode(mode)
|
||||
if !isValid {
|
||||
if !volume.ValidMountMode(mode) {
|
||||
return nil, fmt.Errorf("invalid mode for volumes-from: %s", mode)
|
||||
}
|
||||
bind.RW = isRw
|
||||
bind.RW = volume.ReadWrite(mode)
|
||||
// Mode field is used by SELinux to decide whether to apply label
|
||||
bind.Mode = mode
|
||||
default:
|
||||
|
@ -268,7 +267,7 @@ func parseVolumesFrom(spec string) (string, string, error) {
|
|||
|
||||
if len(specParts) == 2 {
|
||||
mode = specParts[1]
|
||||
if isValid, _ := volume.ValidateMountMode(mode); !isValid {
|
||||
if !volume.ValidMountMode(mode) {
|
||||
return "", "", fmt.Errorf("invalid mode for volumes-from: %s", mode)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -202,7 +202,7 @@ func validatePath(val string, validateMountMode bool) (string, error) {
|
|||
containerPath = splited[0]
|
||||
val = path.Clean(containerPath)
|
||||
case 2:
|
||||
if isValid, _ := volume.ValidateMountMode(splited[1]); validateMountMode && isValid {
|
||||
if isValid := volume.ValidMountMode(splited[1]); validateMountMode && isValid {
|
||||
containerPath = splited[0]
|
||||
mode = splited[1]
|
||||
val = fmt.Sprintf("%s:%s", path.Clean(containerPath), mode)
|
||||
|
@ -213,7 +213,7 @@ func validatePath(val string, validateMountMode bool) (string, error) {
|
|||
case 3:
|
||||
containerPath = splited[1]
|
||||
mode = splited[2]
|
||||
if isValid, _ := volume.ValidateMountMode(splited[2]); validateMountMode && !isValid {
|
||||
if isValid := volume.ValidMountMode(splited[2]); validateMountMode && !isValid {
|
||||
return val, fmt.Errorf("bad mount mode specified : %s", mode)
|
||||
}
|
||||
val = fmt.Sprintf("%s:%s:%s", splited[0], containerPath, mode)
|
||||
|
|
|
@ -49,13 +49,13 @@ var roModes = map[string]bool{
|
|||
"Z,ro": true,
|
||||
}
|
||||
|
||||
// ValidateMountMode will make sure the mount mode is valid.
|
||||
// returns if it's a valid mount mode and if it's read-write or not.
|
||||
func ValidateMountMode(mode string) (bool, bool) {
|
||||
return roModes[mode] || rwModes[mode], rwModes[mode]
|
||||
// ValidMountMode will make sure the mount mode is valid.
|
||||
// returns if it's a valid mount mode or not.
|
||||
func ValidMountMode(mode string) bool {
|
||||
return roModes[mode] || rwModes[mode]
|
||||
}
|
||||
|
||||
// ReadWrite tells you if a mode string is a valid read-only mode or not.
|
||||
// ReadWrite tells you if a mode string is a valid read-write mode or not.
|
||||
func ReadWrite(mode string) bool {
|
||||
return rwModes[mode]
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче