mirror of
				https://github.com/moby/moby.git
				synced 2022-11-09 12:21:53 -05:00 
			
		
		
		
	Don't attempt to evaluate drive root on Windows
Signed-off-by: Darren Stahl <darst@microsoft.com>
This commit is contained in:
		
							parent
							
								
									48c615f853
								
							
						
					
					
						commit
						fdce2a7775
					
				
					 4 changed files with 30 additions and 8 deletions
				
			
		| 
						 | 
				
			
			@ -3022,14 +3022,17 @@ func (s *DockerSuite) TestBuildOnBuild(c *check.C) {
 | 
			
		|||
 | 
			
		||||
// gh #2446
 | 
			
		||||
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"
 | 
			
		||||
	ctx, err := fakeContext(`FROM busybox
 | 
			
		||||
        RUN mkdir /foo
 | 
			
		||||
        RUN ln -s /foo /bar
 | 
			
		||||
        RUN sh -c "mkdir /foo"
 | 
			
		||||
        RUN `+makeLink+`
 | 
			
		||||
        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{
 | 
			
		||||
			"foo": "hello",
 | 
			
		||||
		})
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -95,8 +95,8 @@ func evalSymlinksInScope(path, root string) (string, error) {
 | 
			
		|||
		// root gets prepended and we Clean again (to remove any trailing slash
 | 
			
		||||
		// if the first Clean gave us just "/")
 | 
			
		||||
		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()
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			@ -113,7 +113,8 @@ func evalSymlinksInScope(path, root string) (string, error) {
 | 
			
		|||
			return "", err
 | 
			
		||||
		}
 | 
			
		||||
		if fi.Mode()&os.ModeSymlink == 0 {
 | 
			
		||||
			b.WriteString(p + string(filepath.Separator))
 | 
			
		||||
			b.WriteString(p)
 | 
			
		||||
			b.WriteRune(filepath.Separator)
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,3 +9,7 @@ import (
 | 
			
		|||
func evalSymlinks(path string) (string, error) {
 | 
			
		||||
	return filepath.EvalSymlinks(path)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func isDriveOrRoot(p string) bool {
 | 
			
		||||
	return p == string(filepath.Separator)
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -153,3 +153,17 @@ func walkSymlinks(path string) (string, error) {
 | 
			
		|||
	}
 | 
			
		||||
	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
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue