mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Extract workingdir validation/conversion to a function
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
c0697c27aa
commit
5fc0f03426
1 changed files with 26 additions and 17 deletions
|
@ -235,23 +235,8 @@ func (daemon *Daemon) setHostConfig(container *container.Container, hostConfig *
|
||||||
func (daemon *Daemon) verifyContainerSettings(platform string, hostConfig *containertypes.HostConfig, config *containertypes.Config, update bool) (warnings []string, err error) {
|
func (daemon *Daemon) verifyContainerSettings(platform string, hostConfig *containertypes.HostConfig, config *containertypes.Config, update bool) (warnings []string, err error) {
|
||||||
// First perform verification of settings common across all platforms.
|
// First perform verification of settings common across all platforms.
|
||||||
if config != nil {
|
if config != nil {
|
||||||
if config.WorkingDir != "" {
|
if err := translateWorkingDir(config, platform); err != nil {
|
||||||
wdInvalid := false
|
return nil, err
|
||||||
if runtime.GOOS == platform {
|
|
||||||
config.WorkingDir = filepath.FromSlash(config.WorkingDir) // Ensure in platform semantics
|
|
||||||
if !system.IsAbs(config.WorkingDir) {
|
|
||||||
wdInvalid = true
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// LCOW. Force Unix semantics
|
|
||||||
config.WorkingDir = strings.Replace(config.WorkingDir, string(os.PathSeparator), "/", -1)
|
|
||||||
if !path.IsAbs(config.WorkingDir) {
|
|
||||||
wdInvalid = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if wdInvalid {
|
|
||||||
return nil, fmt.Errorf("the working directory '%s' is invalid, it needs to be an absolute path", config.WorkingDir)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(config.StopSignal) > 0 {
|
if len(config.StopSignal) > 0 {
|
||||||
|
@ -367,3 +352,27 @@ func validateRestartPolicy(policy containertypes.RestartPolicy) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// translateWorkingDir translates the working-dir for the target platform,
|
||||||
|
// and returns an error if the given path is not an absolute path.
|
||||||
|
func translateWorkingDir(config *containertypes.Config, platform string) error {
|
||||||
|
if config.WorkingDir == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
wd := config.WorkingDir
|
||||||
|
switch {
|
||||||
|
case runtime.GOOS != platform:
|
||||||
|
// LCOW. Force Unix semantics
|
||||||
|
wd = strings.Replace(wd, string(os.PathSeparator), "/", -1)
|
||||||
|
if !path.IsAbs(wd) {
|
||||||
|
return fmt.Errorf("the working directory '%s' is invalid, it needs to be an absolute path", config.WorkingDir)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
wd = filepath.FromSlash(wd) // Ensure in platform semantics
|
||||||
|
if !system.IsAbs(wd) {
|
||||||
|
return fmt.Errorf("the working directory '%s' is invalid, it needs to be an absolute path", config.WorkingDir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
config.WorkingDir = wd
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue