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:
commit
45b43d85ec
2 changed files with 27 additions and 0 deletions
|
@ -998,3 +998,21 @@ func TestBuildOnBuildForbiddenMaintainerTrigger(t *testing.T) {
|
||||||
t.Fatal("Error should not be nil")
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -395,9 +395,18 @@ func (b *buildFile) checkPathForAddition(orig string) error {
|
||||||
|
|
||||||
func (b *buildFile) addContext(container *runtime.Container, orig, dest string, remote bool) error {
|
func (b *buildFile) addContext(container *runtime.Container, orig, dest string, remote bool) error {
|
||||||
var (
|
var (
|
||||||
|
err error
|
||||||
origPath = path.Join(b.contextPath, orig)
|
origPath = path.Join(b.contextPath, orig)
|
||||||
destPath = path.Join(container.RootfsPath(), dest)
|
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 '/'
|
// Preserve the trailing '/'
|
||||||
if strings.HasSuffix(dest, "/") {
|
if strings.HasSuffix(dest, "/") {
|
||||||
destPath = destPath + "/"
|
destPath = destPath + "/"
|
||||||
|
|
Loading…
Add table
Reference in a new issue