From 50372973884d96ee115094336ed1952b1e71250a Mon Sep 17 00:00:00 2001 From: Chen Hanxiao Date: Fri, 10 Apr 2015 00:08:05 -0400 Subject: [PATCH] cp: add support for copy filename with ":" We use ":" as separator CONTAINER:PATH. This patch enables copy filename with ":" to host. Signed-off-by: Chen Hanxiao --- api/client/cp.go | 3 ++- integration-cli/docker_cli_cp_test.go | 32 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/api/client/cp.go b/api/client/cp.go index f32e55187f..392e362929 100644 --- a/api/client/cp.go +++ b/api/client/cp.go @@ -21,7 +21,8 @@ func (cli *DockerCli) CmdCp(args ...string) error { cmd.ParseFlags(args, true) - info := strings.Split(cmd.Arg(0), ":") + // deal with path name with `:` + info := strings.SplitN(cmd.Arg(0), ":", 2) if len(info) != 2 { return fmt.Errorf("Error: Path not specified") diff --git a/integration-cli/docker_cli_cp_test.go b/integration-cli/docker_cli_cp_test.go index 37e4659e91..12da76abca 100644 --- a/integration-cli/docker_cli_cp_test.go +++ b/integration-cli/docker_cli_cp_test.go @@ -620,3 +620,35 @@ func TestCpToStdout(t *testing.T) { } logDone("cp - to stdout") } + +func TestCpNameHasColon(t *testing.T) { + testRequires(t, SameHostDaemon) + + out, exitCode, err := dockerCmd(t, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /te:s:t") + if err != nil || exitCode != 0 { + t.Fatal("failed to create a container", out, err) + } + + cleanedContainerID := strings.TrimSpace(out) + defer deleteContainer(cleanedContainerID) + + out, _, err = dockerCmd(t, "wait", cleanedContainerID) + if err != nil || strings.TrimSpace(out) != "0" { + t.Fatal("failed to set up container", out, err) + } + + tmpdir, err := ioutil.TempDir("", "docker-integration") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(tmpdir) + _, _, err = dockerCmd(t, "cp", cleanedContainerID+":/te:s:t", tmpdir) + if err != nil { + t.Fatalf("couldn't docker cp to %s: %s", tmpdir, err) + } + content, err := ioutil.ReadFile(tmpdir + "/te:s:t") + if string(content) != "lololol\n" { + t.Fatalf("Wrong content in copied file %q, should be %q", content, "lololol\n") + } + logDone("cp - copy filename has ':'") +}