summaryrefslogtreecommitdiff
path: root/integration-cli/docker_cli_cp_test.go
diff options
context:
space:
mode:
authorZhang Wei <zhangwei555@huawei.com>2015-10-01 15:56:39 +0800
committerZhang Wei <zhangwei555@huawei.com>2015-11-21 00:36:56 +0800
commit92600bdec1284f9031868751f61bef476d2e1dbd (patch)
treed238185f5570399fbef711bf9f2b7f95d7be2ba7 /integration-cli/docker_cli_cp_test.go
parent0d2ea52f03f2b62e5053ed056fc4db6ab305a6bc (diff)
downloaddocker-92600bdec1284f9031868751f61bef476d2e1dbd.tar.gz
Add '-L' option for `cp`
Fixes #16555 Original docker `cp` always copy symbol link itself instead of target, now we provide '-L' option to allow docker to follow symbol link to real target. Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
Diffstat (limited to 'integration-cli/docker_cli_cp_test.go')
-rw-r--r--integration-cli/docker_cli_cp_test.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/integration-cli/docker_cli_cp_test.go b/integration-cli/docker_cli_cp_test.go
index 384473551a..fd48cd6c96 100644
--- a/integration-cli/docker_cli_cp_test.go
+++ b/integration-cli/docker_cli_cp_test.go
@@ -609,3 +609,57 @@ func (s *DockerSuite) TestCopyCreatedContainer(c *check.C) {
defer os.RemoveAll(tmpDir)
dockerCmd(c, "cp", "test_cp:/bin/sh", tmpDir)
}
+
+// test copy with option `-L`: following symbol link
+// Check that symlinks to a file behave as expected when copying one from
+// a container to host following symbol link
+func (s *DockerSuite) TestCpSymlinkFromConToHostFollowSymlink(c *check.C) {
+ testRequires(c, DaemonIsLinux)
+ out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpFullPath+" /dir_link")
+ if exitCode != 0 {
+ c.Fatal("failed to create a container", out)
+ }
+
+ cleanedContainerID := strings.TrimSpace(out)
+
+ out, _ = dockerCmd(c, "wait", cleanedContainerID)
+ if strings.TrimSpace(out) != "0" {
+ c.Fatal("failed to set up container", out)
+ }
+
+ testDir, err := ioutil.TempDir("", "test-cp-symlink-container-to-host-follow-symlink")
+ if err != nil {
+ c.Fatal(err)
+ }
+ defer os.RemoveAll(testDir)
+
+ // This copy command should copy the symlink, not the target, into the
+ // temporary directory.
+ dockerCmd(c, "cp", "-L", cleanedContainerID+":"+"/dir_link", testDir)
+
+ expectedPath := filepath.Join(testDir, "dir_link")
+
+ expected := []byte(cpContainerContents)
+ actual, err := ioutil.ReadFile(expectedPath)
+
+ if !bytes.Equal(actual, expected) {
+ c.Fatalf("Expected copied file to be duplicate of the container symbol link target")
+ }
+ os.Remove(expectedPath)
+
+ // now test copy symbol link to an non-existing file in host
+ expectedPath = filepath.Join(testDir, "somefile_host")
+ // expectedPath shouldn't exist, if exists, remove it
+ if _, err := os.Lstat(expectedPath); err == nil {
+ os.Remove(expectedPath)
+ }
+
+ dockerCmd(c, "cp", "-L", cleanedContainerID+":"+"/dir_link", expectedPath)
+
+ actual, err = ioutil.ReadFile(expectedPath)
+
+ if !bytes.Equal(actual, expected) {
+ c.Fatalf("Expected copied file to be duplicate of the container symbol link target")
+ }
+ defer os.Remove(expectedPath)
+}