mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #26428 from darrenstahlmsft/AddToSymlink
Don't attempt to evaluate drive root on Windows
This commit is contained in:
commit
c1f2776bf1
4 changed files with 30 additions and 8 deletions
|
@ -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 sh -c "mkdir /foo"
|
||||||
RUN ln -s /foo /bar
|
RUN `+makeLink+`
|
||||||
ADD foo /bar/
|
ADD foo /bar/
|
||||||
RUN [ -f /bar/foo ]
|
RUN sh -c "[ -f /bar/foo ]"
|
||||||
RUN [ -f /foo/foo ]`,
|
RUN sh -c "[ -f /foo/foo ]"`,
|
||||||
map[string]string{
|
map[string]string{
|
||||||
"foo": "hello",
|
"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
|
// 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) {
|
if isDriveOrRoot(cleanP) {
|
||||||
// never Lstat "/" itself
|
// 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue