1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #4873 from crosbymichael/add-internal-symlinks

Follow symlinks inside container root for build's ADD
This commit is contained in:
Guillaume J. Charmes 2014-03-27 15:46:48 -07:00
commit 45b43d85ec
2 changed files with 27 additions and 0 deletions

View file

@ -998,3 +998,21 @@ func TestBuildOnBuildForbiddenMaintainerTrigger(t *testing.T) {
t.Fatal("Error should not be nil")
}
}
// gh #2446
func TestBuildAddToSymlinkDest(t *testing.T) {
eng := NewTestEngine(t)
defer nuke(mkRuntimeFromEngine(eng, t))
_, err := buildImage(testContextTemplate{`
from {IMAGE}
run mkdir /foo
run ln -s /foo /bar
add foo /bar/
run stat /bar/foo
`,
[][2]string{{"foo", "HEYO"}}, nil}, t, eng, true)
if err != nil {
t.Fatal(err)
}
}

View file

@ -395,9 +395,18 @@ func (b *buildFile) checkPathForAddition(orig string) error {
func (b *buildFile) addContext(container *runtime.Container, orig, dest string, remote bool) error {
var (
err error
origPath = path.Join(b.contextPath, orig)
destPath = path.Join(container.RootfsPath(), dest)
)
if destPath != container.RootfsPath() {
destPath, err = utils.FollowSymlinkInScope(destPath, container.RootfsPath())
if err != nil {
return err
}
}
// Preserve the trailing '/'
if strings.HasSuffix(dest, "/") {
destPath = destPath + "/"