Browse Source

Merge pull request #20782 from estesp/new-parent-dir-ownership

Fix ownership of non-existing parent dir
Sebastiaan van Stijn 9 years ago
parent
commit
67b16c7381
2 changed files with 21 additions and 1 deletions
  1. 20 0
      integration-cli/docker_cli_build_test.go
  2. 1 1
      pkg/archive/archive.go

+ 20 - 0
integration-cli/docker_cli_build_test.go

@@ -824,6 +824,26 @@ RUN [ $(ls -l /exists/exists_file | awk '{print $3":"$4}') = 'dockerio:dockerio'
 	}
 	}
 }
 }
 
 
+func (s *DockerSuite) TestBuildCopyToNewParentDirectory(c *check.C) {
+	testRequires(c, DaemonIsLinux) // Linux specific test
+	name := "testcopytonewdir"
+	ctx, err := fakeContext(`FROM busybox
+COPY test_dir /new_dir
+RUN [ $(ls -l / | grep new_dir | awk '{print $3":"$4}') = 'root:root' ]
+RUN ls -l /new_dir`,
+		map[string]string{
+			"test_dir/test_file": "test file",
+		})
+	if err != nil {
+		c.Fatal(err)
+	}
+	defer ctx.Close()
+
+	if _, err := buildImageFromContext(name, ctx, true); err != nil {
+		c.Fatal(err)
+	}
+}
+
 func (s *DockerSuite) TestBuildAddMultipleFilesToFile(c *check.C) {
 func (s *DockerSuite) TestBuildAddMultipleFilesToFile(c *check.C) {
 	name := "testaddmultiplefilestofile"
 	name := "testaddmultiplefilestofile"
 
 

+ 1 - 1
pkg/archive/archive.go

@@ -664,7 +664,7 @@ loop:
 			parent := filepath.Dir(hdr.Name)
 			parent := filepath.Dir(hdr.Name)
 			parentPath := filepath.Join(dest, parent)
 			parentPath := filepath.Join(dest, parent)
 			if _, err := os.Lstat(parentPath); err != nil && os.IsNotExist(err) {
 			if _, err := os.Lstat(parentPath); err != nil && os.IsNotExist(err) {
-				err = system.MkdirAll(parentPath, 0777)
+				err = idtools.MkdirAllNewAs(parentPath, 0777, remappedRootUID, remappedRootGID)
 				if err != nil {
 				if err != nil {
 					return err
 					return err
 				}
 				}