Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -235,23 +235,8 @@ func (daemon *Daemon) setHostConfig(container *container.Container, hostConfig * |
| 235 | 235 |
func (daemon *Daemon) verifyContainerSettings(platform string, hostConfig *containertypes.HostConfig, config *containertypes.Config, update bool) (warnings []string, err error) {
|
| 236 | 236 |
// First perform verification of settings common across all platforms. |
| 237 | 237 |
if config != nil {
|
| 238 |
- if config.WorkingDir != "" {
|
|
| 239 |
- wdInvalid := false |
|
| 240 |
- if runtime.GOOS == platform {
|
|
| 241 |
- config.WorkingDir = filepath.FromSlash(config.WorkingDir) // Ensure in platform semantics |
|
| 242 |
- if !system.IsAbs(config.WorkingDir) {
|
|
| 243 |
- wdInvalid = true |
|
| 244 |
- } |
|
| 245 |
- } else {
|
|
| 246 |
- // LCOW. Force Unix semantics |
|
| 247 |
- config.WorkingDir = strings.Replace(config.WorkingDir, string(os.PathSeparator), "/", -1) |
|
| 248 |
- if !path.IsAbs(config.WorkingDir) {
|
|
| 249 |
- wdInvalid = true |
|
| 250 |
- } |
|
| 251 |
- } |
|
| 252 |
- if wdInvalid {
|
|
| 253 |
- return nil, fmt.Errorf("the working directory '%s' is invalid, it needs to be an absolute path", config.WorkingDir)
|
|
| 254 |
- } |
|
| 238 |
+ if err := translateWorkingDir(config, platform); err != nil {
|
|
| 239 |
+ return nil, err |
|
| 255 | 240 |
} |
| 256 | 241 |
|
| 257 | 242 |
if len(config.StopSignal) > 0 {
|
| ... | ... |
@@ -367,3 +352,27 @@ func validateRestartPolicy(policy containertypes.RestartPolicy) error {
|
| 367 | 367 |
} |
| 368 | 368 |
return nil |
| 369 | 369 |
} |
| 370 |
+ |
|
| 371 |
+// translateWorkingDir translates the working-dir for the target platform, |
|
| 372 |
+// and returns an error if the given path is not an absolute path. |
|
| 373 |
+func translateWorkingDir(config *containertypes.Config, platform string) error {
|
|
| 374 |
+ if config.WorkingDir == "" {
|
|
| 375 |
+ return nil |
|
| 376 |
+ } |
|
| 377 |
+ wd := config.WorkingDir |
|
| 378 |
+ switch {
|
|
| 379 |
+ case runtime.GOOS != platform: |
|
| 380 |
+ // LCOW. Force Unix semantics |
|
| 381 |
+ wd = strings.Replace(wd, string(os.PathSeparator), "/", -1) |
|
| 382 |
+ if !path.IsAbs(wd) {
|
|
| 383 |
+ return fmt.Errorf("the working directory '%s' is invalid, it needs to be an absolute path", config.WorkingDir)
|
|
| 384 |
+ } |
|
| 385 |
+ default: |
|
| 386 |
+ wd = filepath.FromSlash(wd) // Ensure in platform semantics |
|
| 387 |
+ if !system.IsAbs(wd) {
|
|
| 388 |
+ return fmt.Errorf("the working directory '%s' is invalid, it needs to be an absolute path", config.WorkingDir)
|
|
| 389 |
+ } |
|
| 390 |
+ } |
|
| 391 |
+ config.WorkingDir = wd |
|
| 392 |
+ return nil |
|
| 393 |
+} |