mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
daemon/archive.go: Fix copy routines to preserve UID.
This changes the long-standing bug of copy operations not preserving the UID/GID information after the files arrive to the container. Signed-off-by: Erik Hollensbe <github@hollensbe.org>
This commit is contained in:
@@ -31,7 +31,7 @@ func (s *DockerSuite) TestCpToErrSrcNotExists(c *check.C) {
|
||||
srcPath := cpPath(tmpDir, "file1")
|
||||
dstPath := containerCpPath(containerID, "file1")
|
||||
|
||||
err := runDockerCp(c, srcPath, dstPath)
|
||||
err := runDockerCp(c, srcPath, dstPath, nil)
|
||||
c.Assert(err, checker.NotNil)
|
||||
|
||||
c.Assert(isCpNotExist(err), checker.True, check.Commentf("expected IsNotExist error, but got %T: %s", err, err))
|
||||
@@ -50,7 +50,7 @@ func (s *DockerSuite) TestCpToErrSrcNotDir(c *check.C) {
|
||||
srcPath := cpPathTrailingSep(tmpDir, "file1")
|
||||
dstPath := containerCpPath(containerID, "testDir")
|
||||
|
||||
err := runDockerCp(c, srcPath, dstPath)
|
||||
err := runDockerCp(c, srcPath, dstPath, nil)
|
||||
c.Assert(err, checker.NotNil)
|
||||
|
||||
c.Assert(isCpNotDir(err), checker.True, check.Commentf("expected IsNotDir error, but got %T: %s", err, err))
|
||||
@@ -71,7 +71,7 @@ func (s *DockerSuite) TestCpToErrDstParentNotExists(c *check.C) {
|
||||
srcPath := cpPath(tmpDir, "file1")
|
||||
dstPath := containerCpPath(containerID, "/notExists", "file1")
|
||||
|
||||
err := runDockerCp(c, srcPath, dstPath)
|
||||
err := runDockerCp(c, srcPath, dstPath, nil)
|
||||
c.Assert(err, checker.NotNil)
|
||||
|
||||
c.Assert(isCpNotExist(err), checker.True, check.Commentf("expected IsNotExist error, but got %T: %s", err, err))
|
||||
@@ -79,7 +79,7 @@ func (s *DockerSuite) TestCpToErrDstParentNotExists(c *check.C) {
|
||||
// Try with a directory source.
|
||||
srcPath = cpPath(tmpDir, "dir1")
|
||||
|
||||
err = runDockerCp(c, srcPath, dstPath)
|
||||
err = runDockerCp(c, srcPath, dstPath, nil)
|
||||
c.Assert(err, checker.NotNil)
|
||||
|
||||
c.Assert(isCpNotExist(err), checker.True, check.Commentf("expected IsNotExist error, but got %T: %s", err, err))
|
||||
@@ -104,7 +104,7 @@ func (s *DockerSuite) TestCpToErrDstNotDir(c *check.C) {
|
||||
// The client should encounter an error trying to stat the destination
|
||||
// and then be unable to copy since the destination is asserted to be a
|
||||
// directory but does not exist.
|
||||
err := runDockerCp(c, srcPath, dstPath)
|
||||
err := runDockerCp(c, srcPath, dstPath, nil)
|
||||
c.Assert(err, checker.NotNil)
|
||||
|
||||
c.Assert(isCpDirNotExist(err), checker.True, check.Commentf("expected DirNotExist error, but got %T: %s", err, err))
|
||||
@@ -116,7 +116,7 @@ func (s *DockerSuite) TestCpToErrDstNotDir(c *check.C) {
|
||||
// then decide to extract to the parent directory instead with a rebased
|
||||
// name in the source archive, but this directory would overwrite the
|
||||
// existing file with the same name.
|
||||
err = runDockerCp(c, srcPath, dstPath)
|
||||
err = runDockerCp(c, srcPath, dstPath, nil)
|
||||
c.Assert(err, checker.NotNil)
|
||||
|
||||
c.Assert(isCannotOverwriteNonDirWithDir(err), checker.True, check.Commentf("expected CannotOverwriteNonDirWithDir error, but got %T: %s", err, err))
|
||||
@@ -144,7 +144,7 @@ func (s *DockerSuite) TestCpToSymlinkDestination(c *check.C) {
|
||||
srcPath := cpPath(testVol, "file2")
|
||||
dstPath := containerCpPath(containerID, "/vol2/symlinkToFile1")
|
||||
|
||||
c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil)
|
||||
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
|
||||
|
||||
// The symlink should not have been modified.
|
||||
c.Assert(symlinkTargetEquals(c, cpPath(testVol, "symlinkToFile1"), "file1"), checker.IsNil)
|
||||
@@ -156,7 +156,7 @@ func (s *DockerSuite) TestCpToSymlinkDestination(c *check.C) {
|
||||
// This should copy the file into the symlink target directory.
|
||||
dstPath = containerCpPath(containerID, "/vol2/symlinkToDir1")
|
||||
|
||||
c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil)
|
||||
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
|
||||
|
||||
// The symlink should not have been modified.
|
||||
c.Assert(symlinkTargetEquals(c, cpPath(testVol, "symlinkToDir1"), "dir1"), checker.IsNil)
|
||||
@@ -169,7 +169,7 @@ func (s *DockerSuite) TestCpToSymlinkDestination(c *check.C) {
|
||||
// contents of the source file.
|
||||
dstPath = containerCpPath(containerID, "/vol2/brokenSymlinkToFileX")
|
||||
|
||||
c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil)
|
||||
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
|
||||
|
||||
// The symlink should not have been modified.
|
||||
c.Assert(symlinkTargetEquals(c, cpPath(testVol, "brokenSymlinkToFileX"), "fileX"), checker.IsNil)
|
||||
@@ -183,7 +183,7 @@ func (s *DockerSuite) TestCpToSymlinkDestination(c *check.C) {
|
||||
srcPath = cpPath(testVol, "/dir2")
|
||||
dstPath = containerCpPath(containerID, "/vol2/symlinkToDir1")
|
||||
|
||||
c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil)
|
||||
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
|
||||
|
||||
// The symlink should not have been modified.
|
||||
c.Assert(symlinkTargetEquals(c, cpPath(testVol, "symlinkToDir1"), "dir1"), checker.IsNil)
|
||||
@@ -197,7 +197,7 @@ func (s *DockerSuite) TestCpToSymlinkDestination(c *check.C) {
|
||||
// should not modify the symlink.
|
||||
dstPath = containerCpPath(containerID, "/vol2/brokenSymlinkToDirX")
|
||||
|
||||
c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil)
|
||||
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
|
||||
|
||||
// The symlink should not have been modified.
|
||||
c.Assert(symlinkTargetEquals(c, cpPath(testVol, "brokenSymlinkToDirX"), "dirX"), checker.IsNil)
|
||||
@@ -238,7 +238,7 @@ func (s *DockerSuite) TestCpToCaseA(c *check.C) {
|
||||
srcPath := cpPath(tmpDir, "file1")
|
||||
dstPath := containerCpPath(containerID, "/root/itWorks.txt")
|
||||
|
||||
c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil)
|
||||
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
|
||||
|
||||
c.Assert(containerStartOutputEquals(c, containerID, "file1\n"), checker.IsNil)
|
||||
}
|
||||
@@ -259,7 +259,7 @@ func (s *DockerSuite) TestCpToCaseB(c *check.C) {
|
||||
srcPath := cpPath(tmpDir, "file1")
|
||||
dstDir := containerCpPathTrailingSep(containerID, "testDir")
|
||||
|
||||
err := runDockerCp(c, srcPath, dstDir)
|
||||
err := runDockerCp(c, srcPath, dstDir, nil)
|
||||
c.Assert(err, checker.NotNil)
|
||||
|
||||
c.Assert(isCpDirNotExist(err), checker.True, check.Commentf("expected DirNotExists error, but got %T: %s", err, err))
|
||||
@@ -285,7 +285,7 @@ func (s *DockerSuite) TestCpToCaseC(c *check.C) {
|
||||
// Ensure the container's file starts with the original content.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, "file2\n"), checker.IsNil)
|
||||
|
||||
c.Assert(runDockerCp(c, srcPath, dstPath), checker.IsNil)
|
||||
c.Assert(runDockerCp(c, srcPath, dstPath, nil), checker.IsNil)
|
||||
|
||||
// Should now contain file1's contents.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, "file1\n"), checker.IsNil)
|
||||
@@ -312,7 +312,7 @@ func (s *DockerSuite) TestCpToCaseD(c *check.C) {
|
||||
// Ensure that dstPath doesn't exist.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil)
|
||||
|
||||
c.Assert(runDockerCp(c, srcPath, dstDir), checker.IsNil)
|
||||
c.Assert(runDockerCp(c, srcPath, dstDir, nil), checker.IsNil)
|
||||
|
||||
// Should now contain file1's contents.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, "file1\n"), checker.IsNil)
|
||||
@@ -330,7 +330,7 @@ func (s *DockerSuite) TestCpToCaseD(c *check.C) {
|
||||
// Ensure that dstPath doesn't exist.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil)
|
||||
|
||||
c.Assert(runDockerCp(c, srcPath, dstDir), checker.IsNil)
|
||||
c.Assert(runDockerCp(c, srcPath, dstDir, nil), checker.IsNil)
|
||||
|
||||
// Should now contain file1's contents.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, "file1\n"), checker.IsNil)
|
||||
@@ -353,7 +353,7 @@ func (s *DockerSuite) TestCpToCaseE(c *check.C) {
|
||||
srcDir := cpPath(tmpDir, "dir1")
|
||||
dstDir := containerCpPath(containerID, "testDir")
|
||||
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil)
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
|
||||
|
||||
// Should now contain file1-1's contents.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
|
||||
@@ -367,7 +367,7 @@ func (s *DockerSuite) TestCpToCaseE(c *check.C) {
|
||||
|
||||
dstDir = containerCpPathTrailingSep(containerID, "testDir")
|
||||
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil)
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
|
||||
|
||||
// Should now contain file1-1's contents.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
|
||||
@@ -389,7 +389,7 @@ func (s *DockerSuite) TestCpToCaseF(c *check.C) {
|
||||
srcDir := cpPath(tmpDir, "dir1")
|
||||
dstFile := containerCpPath(containerID, "/root/file1")
|
||||
|
||||
err := runDockerCp(c, srcDir, dstFile)
|
||||
err := runDockerCp(c, srcDir, dstFile, nil)
|
||||
c.Assert(err, checker.NotNil)
|
||||
|
||||
c.Assert(isCpCannotCopyDir(err), checker.True, check.Commentf("expected ErrCannotCopyDir error, but got %T: %s", err, err))
|
||||
@@ -416,7 +416,7 @@ func (s *DockerSuite) TestCpToCaseG(c *check.C) {
|
||||
// Ensure that dstPath doesn't exist.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil)
|
||||
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil)
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
|
||||
|
||||
// Should now contain file1-1's contents.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
|
||||
@@ -434,7 +434,7 @@ func (s *DockerSuite) TestCpToCaseG(c *check.C) {
|
||||
// Ensure that dstPath doesn't exist.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil)
|
||||
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil)
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
|
||||
|
||||
// Should now contain file1-1's contents.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
|
||||
@@ -457,7 +457,7 @@ func (s *DockerSuite) TestCpToCaseH(c *check.C) {
|
||||
srcDir := cpPathTrailingSep(tmpDir, "dir1") + "."
|
||||
dstDir := containerCpPath(containerID, "testDir")
|
||||
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil)
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
|
||||
|
||||
// Should now contain file1-1's contents.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
|
||||
@@ -471,7 +471,7 @@ func (s *DockerSuite) TestCpToCaseH(c *check.C) {
|
||||
|
||||
dstDir = containerCpPathTrailingSep(containerID, "testDir")
|
||||
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil)
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
|
||||
|
||||
// Should now contain file1-1's contents.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
|
||||
@@ -494,7 +494,7 @@ func (s *DockerSuite) TestCpToCaseI(c *check.C) {
|
||||
srcDir := cpPathTrailingSep(tmpDir, "dir1") + "."
|
||||
dstFile := containerCpPath(containerID, "/root/file1")
|
||||
|
||||
err := runDockerCp(c, srcDir, dstFile)
|
||||
err := runDockerCp(c, srcDir, dstFile, nil)
|
||||
c.Assert(err, checker.NotNil)
|
||||
|
||||
c.Assert(isCpCannotCopyDir(err), checker.True, check.Commentf("expected ErrCannotCopyDir error, but got %T: %s", err, err))
|
||||
@@ -522,7 +522,7 @@ func (s *DockerSuite) TestCpToCaseJ(c *check.C) {
|
||||
// Ensure that dstPath doesn't exist.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil)
|
||||
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil)
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
|
||||
|
||||
// Should now contain file1-1's contents.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
|
||||
@@ -539,7 +539,7 @@ func (s *DockerSuite) TestCpToCaseJ(c *check.C) {
|
||||
// Ensure that dstPath doesn't exist.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, ""), checker.IsNil)
|
||||
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir), checker.IsNil)
|
||||
c.Assert(runDockerCp(c, srcDir, dstDir, nil), checker.IsNil)
|
||||
|
||||
// Should now contain file1-1's contents.
|
||||
c.Assert(containerStartOutputEquals(c, containerID, "file1-1\n"), checker.IsNil)
|
||||
@@ -563,7 +563,7 @@ func (s *DockerSuite) TestCpToErrReadOnlyRootfs(c *check.C) {
|
||||
srcPath := cpPath(tmpDir, "file1")
|
||||
dstPath := containerCpPath(containerID, "/root/shouldNotExist")
|
||||
|
||||
err := runDockerCp(c, srcPath, dstPath)
|
||||
err := runDockerCp(c, srcPath, dstPath, nil)
|
||||
c.Assert(err, checker.NotNil)
|
||||
|
||||
c.Assert(isCpCannotCopyReadOnly(err), checker.True, check.Commentf("expected ErrContainerRootfsReadonly error, but got %T: %s", err, err))
|
||||
@@ -590,7 +590,7 @@ func (s *DockerSuite) TestCpToErrReadOnlyVolume(c *check.C) {
|
||||
srcPath := cpPath(tmpDir, "file1")
|
||||
dstPath := containerCpPath(containerID, "/vol_ro/shouldNotExist")
|
||||
|
||||
err := runDockerCp(c, srcPath, dstPath)
|
||||
err := runDockerCp(c, srcPath, dstPath, nil)
|
||||
c.Assert(err, checker.NotNil)
|
||||
|
||||
c.Assert(isCpCannotCopyReadOnly(err), checker.True, check.Commentf("expected ErrVolumeReadonly error, but got %T: %s", err, err))
|
||||
|
||||
Reference in New Issue
Block a user