浏览代码

Don't attempt to evaluate drive root on Windows

Signed-off-by: Darren Stahl <darst@microsoft.com>
Darren Stahl 8 年之前
父节点
当前提交
fdce2a7775
共有 4 个文件被更改,包括 30 次插入8 次删除
  1. 8 5
      integration-cli/docker_cli_build_test.go
  2. 4 3
      pkg/symlink/fs.go
  3. 4 0
      pkg/symlink/fs_unix.go
  4. 14 0
      pkg/symlink/fs_windows.go

+ 8 - 5
integration-cli/docker_cli_build_test.go

@@ -3022,14 +3022,17 @@ func (s *DockerSuite) TestBuildOnBuild(c *check.C) {
 
 
 // gh #2446
 // gh #2446
 func (s *DockerSuite) TestBuildAddToSymlinkDest(c *check.C) {
 func (s *DockerSuite) TestBuildAddToSymlinkDest(c *check.C) {
-	testRequires(c, DaemonIsLinux)
+	makeLink := `ln -s /foo /bar`
+	if daemonPlatform == "windows" {
+		makeLink = `mklink /D C:\bar C:\foo`
+	}
 	name := "testbuildaddtosymlinkdest"
 	name := "testbuildaddtosymlinkdest"
 	ctx, err := fakeContext(`FROM busybox
 	ctx, err := fakeContext(`FROM busybox
-        RUN mkdir /foo
-        RUN ln -s /foo /bar
+        RUN sh -c "mkdir /foo"
+        RUN `+makeLink+`
         ADD foo /bar/
         ADD foo /bar/
-        RUN [ -f /bar/foo ]
-        RUN [ -f /foo/foo ]`,
+        RUN sh -c "[ -f /bar/foo ]"
+        RUN sh -c "[ -f /foo/foo ]"`,
 		map[string]string{
 		map[string]string{
 			"foo": "hello",
 			"foo": "hello",
 		})
 		})

+ 4 - 3
pkg/symlink/fs.go

@@ -95,8 +95,8 @@ func evalSymlinksInScope(path, root string) (string, error) {
 		// root gets prepended and we Clean again (to remove any trailing slash
 		// root gets prepended and we Clean again (to remove any trailing slash
 		// if the first Clean gave us just "/")
 		// if the first Clean gave us just "/")
 		cleanP := filepath.Clean(string(filepath.Separator) + b.String() + p)
 		cleanP := filepath.Clean(string(filepath.Separator) + b.String() + p)
-		if cleanP == string(filepath.Separator) {
-			// never Lstat "/" itself
+		if isDriveOrRoot(cleanP) {
+			// never Lstat "/" itself, or drive letters on Windows
 			b.Reset()
 			b.Reset()
 			continue
 			continue
 		}
 		}
@@ -113,7 +113,8 @@ func evalSymlinksInScope(path, root string) (string, error) {
 			return "", err
 			return "", err
 		}
 		}
 		if fi.Mode()&os.ModeSymlink == 0 {
 		if fi.Mode()&os.ModeSymlink == 0 {
-			b.WriteString(p + string(filepath.Separator))
+			b.WriteString(p)
+			b.WriteRune(filepath.Separator)
 			continue
 			continue
 		}
 		}
 
 

+ 4 - 0
pkg/symlink/fs_unix.go

@@ -9,3 +9,7 @@ import (
 func evalSymlinks(path string) (string, error) {
 func evalSymlinks(path string) (string, error) {
 	return filepath.EvalSymlinks(path)
 	return filepath.EvalSymlinks(path)
 }
 }
+
+func isDriveOrRoot(p string) bool {
+	return p == string(filepath.Separator)
+}

+ 14 - 0
pkg/symlink/fs_windows.go

@@ -153,3 +153,17 @@ func walkSymlinks(path string) (string, error) {
 	}
 	}
 	return filepath.Clean(b.String()), nil
 	return filepath.Clean(b.String()), nil
 }
 }
+
+func isDriveOrRoot(p string) bool {
+	if p == string(filepath.Separator) {
+		return true
+	}
+
+	length := len(p)
+	if length >= 2 {
+		if p[length-1] == ':' && (('a' <= p[length-2] && p[length-2] <= 'z') || ('A' <= p[length-2] && p[length-2] <= 'Z')) {
+			return true
+		}
+	}
+	return false
+}