Browse code

Merge pull request #15865 from Microsoft/10662-isabs

Windows: Fix use of IsAbs check

Alexander Morozov authored on 2015/08/27 05:29:24
Showing 3 changed files
... ...
@@ -1052,7 +1052,7 @@ func (daemon *Daemon) verifyContainerSettings(hostConfig *runconfig.HostConfig,
1052 1052
 
1053 1053
 	// First perform verification of settings common across all platforms.
1054 1054
 	if config != nil {
1055
-		if config.WorkingDir != "" && !filepath.IsAbs(config.WorkingDir) {
1055
+		if config.WorkingDir != "" && !system.IsAbs(config.WorkingDir) {
1056 1056
 			return nil, fmt.Errorf("The working directory '%s' is invalid. It needs to be an absolute path.", config.WorkingDir)
1057 1057
 		}
1058 1058
 	}
... ...
@@ -4,6 +4,7 @@ package system
4 4
 
5 5
 import (
6 6
 	"os"
7
+	"path/filepath"
7 8
 )
8 9
 
9 10
 // MkdirAll creates a directory named path along with any necessary parents,
... ...
@@ -11,3 +12,8 @@ import (
11 11
 func MkdirAll(path string, perm os.FileMode) error {
12 12
 	return os.MkdirAll(path, perm)
13 13
 }
14
+
15
+// IsAbs is a platform-specific wrapper for filepath.IsAbs.
16
+func IsAbs(path string) bool {
17
+	return filepath.IsAbs(path)
18
+}
... ...
@@ -4,7 +4,9 @@ package system
4 4
 
5 5
 import (
6 6
 	"os"
7
+	"path/filepath"
7 8
 	"regexp"
9
+	"strings"
8 10
 	"syscall"
9 11
 )
10 12
 
... ...
@@ -62,3 +64,19 @@ func MkdirAll(path string, perm os.FileMode) error {
62 62
 	}
63 63
 	return nil
64 64
 }
65
+
66
+// IsAbs is a platform-specific wrapper for filepath.IsAbs. On Windows,
67
+// golang filepath.IsAbs does not consider a path \windows\system32 as absolute
68
+// as it doesn't start with a drive-letter/colon combination. However, in
69
+// docker we need to verify things such as WORKDIR /windows/system32 in
70
+// a Dockerfile (which gets translated to \windows\system32 when being processed
71
+// by the daemon. This SHOULD be treated as absolute from a docker processing
72
+// perspective.
73
+func IsAbs(path string) bool {
74
+	if !filepath.IsAbs(path) {
75
+		if !strings.HasPrefix(path, string(os.PathSeparator)) {
76
+			return false
77
+		}
78
+	}
79
+	return true
80
+}