Browse code

Signed-off-by: John Howard <jhoward@microsoft.com>

Revert "Combine SetupWorkingDirectory for Linux and Windows"

This reverts commit ec31741ca186278ea60faf49f85087c493e78806.

John Howard authored on 2016/01/30 13:44:34
Showing 4 changed files
... ...
@@ -22,7 +22,6 @@ import (
22 22
 	"github.com/docker/docker/pkg/promise"
23 23
 	"github.com/docker/docker/pkg/signal"
24 24
 	"github.com/docker/docker/pkg/symlink"
25
-	"github.com/docker/docker/pkg/system"
26 25
 	"github.com/docker/docker/runconfig"
27 26
 	"github.com/docker/docker/volume"
28 27
 	containertypes "github.com/docker/engine-api/types/container"
... ...
@@ -184,34 +183,6 @@ func (container *Container) WriteHostConfig() error {
184 184
 	return json.NewEncoder(f).Encode(&container.HostConfig)
185 185
 }
186 186
 
187
-// SetupWorkingDirectory sets up the container's working directory as set in container.Config.WorkingDir
188
-func (container *Container) SetupWorkingDirectory() error {
189
-	if container.Config.WorkingDir == "" {
190
-		return nil
191
-	}
192
-	container.Config.WorkingDir = filepath.Clean(container.Config.WorkingDir)
193
-
194
-	pth, err := container.GetResourcePath(container.Config.WorkingDir)
195
-	if err != nil {
196
-		return err
197
-	}
198
-
199
-	pthInfo, err := os.Stat(pth)
200
-	if err != nil {
201
-		if !os.IsNotExist(err) {
202
-			return err
203
-		}
204
-
205
-		if err := system.MkdirAll(pth, 0755); err != nil {
206
-			return err
207
-		}
208
-	}
209
-	if pthInfo != nil && !pthInfo.IsDir() {
210
-		return derr.ErrorCodeNotADir.WithArgs(container.Config.WorkingDir)
211
-	}
212
-	return nil
213
-}
214
-
215 187
 // GetResourcePath evaluates `path` in the scope of the container's BaseFS, with proper path
216 188
 // sanitisation. Symlinks are all scoped to the BaseFS of the container, as
217 189
 // though the container's BaseFS was `/`.
... ...
@@ -398,6 +398,34 @@ func (container *Container) BuildCreateEndpointOptions(n libnetwork.Network, epC
398 398
 	return createOptions, nil
399 399
 }
400 400
 
401
+// SetupWorkingDirectory sets up the container's working directory as set in container.Config.WorkingDir
402
+func (container *Container) SetupWorkingDirectory() error {
403
+	if container.Config.WorkingDir == "" {
404
+		return nil
405
+	}
406
+	container.Config.WorkingDir = filepath.Clean(container.Config.WorkingDir)
407
+
408
+	pth, err := container.GetResourcePath(container.Config.WorkingDir)
409
+	if err != nil {
410
+		return err
411
+	}
412
+
413
+	pthInfo, err := os.Stat(pth)
414
+	if err != nil {
415
+		if !os.IsNotExist(err) {
416
+			return err
417
+		}
418
+
419
+		if err := system.MkdirAll(pth, 0755); err != nil {
420
+			return err
421
+		}
422
+	}
423
+	if pthInfo != nil && !pthInfo.IsDir() {
424
+		return derr.ErrorCodeNotADir.WithArgs(container.Config.WorkingDir)
425
+	}
426
+	return nil
427
+}
428
+
401 429
 // appendNetworkMounts appends any network mounts to the array of mount points passed in
402 430
 func appendNetworkMounts(container *Container, volumeMounts []volume.MountPoint) ([]volume.MountPoint, error) {
403 431
 	for _, mnt := range container.NetworkMounts() {
... ...
@@ -22,6 +22,12 @@ func (container *Container) CreateDaemonEnvironment(linkedEnv []string) []string
22 22
 	return container.Config.Env
23 23
 }
24 24
 
25
+// SetupWorkingDirectory initializes the container working directory.
26
+// This is a NOOP In windows.
27
+func (container *Container) SetupWorkingDirectory() error {
28
+	return nil
29
+}
30
+
25 31
 // UnmountIpcMounts unmount Ipc related mounts.
26 32
 // This is a NOOP on windows.
27 33
 func (container *Container) UnmountIpcMounts(unmount func(pth string) error) {
... ...
@@ -1724,7 +1724,7 @@ func (s *DockerSuite) TestRunWorkdirExistsAndIsFile(c *check.C) {
1724 1724
 	expected := "Cannot mkdir: /bin/cat is not a directory"
1725 1725
 	if daemonPlatform == "windows" {
1726 1726
 		existingFile = `\windows\system32\ntdll.dll`
1727
-		expected = `Cannot mkdir: \windows\system32\ntdll.dll is not a directory.`
1727
+		expected = "The directory name is invalid"
1728 1728
 	}
1729 1729
 
1730 1730
 	out, exitCode, err := dockerCmdWithError("run", "-w", existingFile, "busybox")