mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #12222 from chenhanxiao/cp-support-colon
cp: add support for copy filename with ":"
This commit is contained in:
commit
75b911eb3c
2 changed files with 34 additions and 1 deletions
|
@ -21,7 +21,8 @@ func (cli *DockerCli) CmdCp(args ...string) error {
|
||||||
|
|
||||||
cmd.ParseFlags(args, true)
|
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 {
|
if len(info) != 2 {
|
||||||
return fmt.Errorf("Error: Path not specified")
|
return fmt.Errorf("Error: Path not specified")
|
||||||
|
|
|
@ -620,3 +620,35 @@ func TestCpToStdout(t *testing.T) {
|
||||||
}
|
}
|
||||||
logDone("cp - to stdout")
|
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 ':'")
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue