| ... | ... |
@@ -998,3 +998,21 @@ func TestBuildOnBuildForbiddenMaintainerTrigger(t *testing.T) {
|
| 998 | 998 |
t.Fatal("Error should not be nil")
|
| 999 | 999 |
} |
| 1000 | 1000 |
} |
| 1001 |
+ |
|
| 1002 |
+// gh #2446 |
|
| 1003 |
+func TestBuildAddToSymlinkDest(t *testing.T) {
|
|
| 1004 |
+ eng := NewTestEngine(t) |
|
| 1005 |
+ defer nuke(mkRuntimeFromEngine(eng, t)) |
|
| 1006 |
+ |
|
| 1007 |
+ _, err := buildImage(testContextTemplate{`
|
|
| 1008 |
+ from {IMAGE}
|
|
| 1009 |
+ run mkdir /foo |
|
| 1010 |
+ run ln -s /foo /bar |
|
| 1011 |
+ add foo /bar/ |
|
| 1012 |
+ run stat /bar/foo |
|
| 1013 |
+ `, |
|
| 1014 |
+ [][2]string{{"foo", "HEYO"}}, nil}, t, eng, true)
|
|
| 1015 |
+ if err != nil {
|
|
| 1016 |
+ t.Fatal(err) |
|
| 1017 |
+ } |
|
| 1018 |
+} |
| ... | ... |
@@ -395,9 +395,18 @@ func (b *buildFile) checkPathForAddition(orig string) error {
|
| 395 | 395 |
|
| 396 | 396 |
func (b *buildFile) addContext(container *runtime.Container, orig, dest string, remote bool) error {
|
| 397 | 397 |
var ( |
| 398 |
+ err error |
|
| 398 | 399 |
origPath = path.Join(b.contextPath, orig) |
| 399 | 400 |
destPath = path.Join(container.RootfsPath(), dest) |
| 400 | 401 |
) |
| 402 |
+ |
|
| 403 |
+ if destPath != container.RootfsPath() {
|
|
| 404 |
+ destPath, err = utils.FollowSymlinkInScope(destPath, container.RootfsPath()) |
|
| 405 |
+ if err != nil {
|
|
| 406 |
+ return err |
|
| 407 |
+ } |
|
| 408 |
+ } |
|
| 409 |
+ |
|
| 401 | 410 |
// Preserve the trailing '/' |
| 402 | 411 |
if strings.HasSuffix(dest, "/") {
|
| 403 | 412 |
destPath = destPath + "/" |