1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

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 <chenhanxiao@cn.fujitsu.com>
This commit is contained in:
Chen Hanxiao 2015-04-10 00:08:05 -04:00
parent e690ad9292
commit 5037297388
2 changed files with 34 additions and 1 deletions

View file

@ -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")

View file

@ -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 ':'")
}