integration-cli/docker_cli_cp_test.go
79ca77f3
 package main
 
 import (
ef98fe07
 	"bytes"
79ca77f3
 	"fmt"
 	"io/ioutil"
 	"os"
5eef0a28
 	"os/exec"
c5b312dc
 	"path"
79ca77f3
 	"path/filepath"
f3d96e81
 	"strings"
dc944ea7
 
 	"github.com/go-check/check"
79ca77f3
 )
 
 const (
 	cpTestPathParent = "/some"
 	cpTestPath       = "/some/path"
 	cpTestName       = "test"
 	cpFullPath       = "/some/path/test"
 
 	cpContainerContents = "holla, i am the container"
 	cpHostContents      = "hello, i am the host"
 )
 
 // Test for #5656
 // Check that garbage paths don't escape the container's rootfs
dc944ea7
 func (s *DockerSuite) TestCpGarbagePath(c *check.C) {
 	out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath)
621b601b
 	if exitCode != 0 {
dc944ea7
 		c.Fatal("failed to create a container", out)
79ca77f3
 	}
 
475c6531
 	cleanedContainerID := strings.TrimSpace(out)
79ca77f3
 
dc944ea7
 	out, _ = dockerCmd(c, "wait", cleanedContainerID)
621b601b
 	if strings.TrimSpace(out) != "0" {
dc944ea7
 		c.Fatal("failed to set up container", out)
79ca77f3
 	}
 
 	if err := os.MkdirAll(cpTestPath, os.ModeDir); err != nil {
dc944ea7
 		c.Fatal(err)
79ca77f3
 	}
 
 	hostFile, err := os.Create(cpFullPath)
 	if err != nil {
dc944ea7
 		c.Fatal(err)
79ca77f3
 	}
 	defer hostFile.Close()
 	defer os.RemoveAll(cpTestPathParent)
 
 	fmt.Fprintf(hostFile, "%s", cpHostContents)
 
 	tmpdir, err := ioutil.TempDir("", "docker-integration")
 	if err != nil {
dc944ea7
 		c.Fatal(err)
79ca77f3
 	}
 
 	tmpname := filepath.Join(tmpdir, cpTestName)
 	defer os.RemoveAll(tmpdir)
 
c5b312dc
 	path := path.Join("../../../../../../../../../../../../", cpFullPath)
79ca77f3
 
dc944ea7
 	_, _ = dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
79ca77f3
 
 	file, _ := os.Open(tmpname)
 	defer file.Close()
 
 	test, err := ioutil.ReadAll(file)
 	if err != nil {
dc944ea7
 		c.Fatal(err)
79ca77f3
 	}
 
 	if string(test) == cpHostContents {
dc944ea7
 		c.Errorf("output matched host file -- garbage path can escape container rootfs")
79ca77f3
 	}
 
 	if string(test) != cpContainerContents {
dc944ea7
 		c.Errorf("output doesn't match the input for garbage path")
79ca77f3
 	}
 
 }
 
 // Check that relative paths are relative to the container's rootfs
dc944ea7
 func (s *DockerSuite) TestCpRelativePath(c *check.C) {
 	out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath)
621b601b
 	if exitCode != 0 {
dc944ea7
 		c.Fatal("failed to create a container", out)
79ca77f3
 	}
 
475c6531
 	cleanedContainerID := strings.TrimSpace(out)
79ca77f3
 
dc944ea7
 	out, _ = dockerCmd(c, "wait", cleanedContainerID)
621b601b
 	if strings.TrimSpace(out) != "0" {
dc944ea7
 		c.Fatal("failed to set up container", out)
79ca77f3
 	}
 
 	if err := os.MkdirAll(cpTestPath, os.ModeDir); err != nil {
dc944ea7
 		c.Fatal(err)
79ca77f3
 	}
 
 	hostFile, err := os.Create(cpFullPath)
 	if err != nil {
dc944ea7
 		c.Fatal(err)
79ca77f3
 	}
 	defer hostFile.Close()
 	defer os.RemoveAll(cpTestPathParent)
 
 	fmt.Fprintf(hostFile, "%s", cpHostContents)
 
 	tmpdir, err := ioutil.TempDir("", "docker-integration")
 
 	if err != nil {
dc944ea7
 		c.Fatal(err)
79ca77f3
 	}
 
 	tmpname := filepath.Join(tmpdir, cpTestName)
 	defer os.RemoveAll(tmpdir)
 
c5b312dc
 	var relPath string
 	if path.IsAbs(cpFullPath) {
 		// normally this is `filepath.Rel("/", cpFullPath)` but we cannot
 		// get this unix-path manipulation on windows with filepath.
 		relPath = cpFullPath[1:]
 	} else {
dc944ea7
 		c.Fatalf("path %s was assumed to be an absolute path", cpFullPath)
c5b312dc
 	}
79ca77f3
 
dc944ea7
 	_, _ = dockerCmd(c, "cp", cleanedContainerID+":"+relPath, tmpdir)
79ca77f3
 
 	file, _ := os.Open(tmpname)
 	defer file.Close()
 
 	test, err := ioutil.ReadAll(file)
 	if err != nil {
dc944ea7
 		c.Fatal(err)
79ca77f3
 	}
 
 	if string(test) == cpHostContents {
dc944ea7
 		c.Errorf("output matched host file -- relative path can escape container rootfs")
79ca77f3
 	}
 
 	if string(test) != cpContainerContents {
dc944ea7
 		c.Errorf("output doesn't match the input for relative path")
79ca77f3
 	}
 
 }
 
 // Check that absolute paths are relative to the container's rootfs
dc944ea7
 func (s *DockerSuite) TestCpAbsolutePath(c *check.C) {
 	out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath)
621b601b
 	if exitCode != 0 {
dc944ea7
 		c.Fatal("failed to create a container", out)
79ca77f3
 	}
 
475c6531
 	cleanedContainerID := strings.TrimSpace(out)
79ca77f3
 
dc944ea7
 	out, _ = dockerCmd(c, "wait", cleanedContainerID)
621b601b
 	if strings.TrimSpace(out) != "0" {
dc944ea7
 		c.Fatal("failed to set up container", out)
79ca77f3
 	}
 
 	if err := os.MkdirAll(cpTestPath, os.ModeDir); err != nil {
dc944ea7
 		c.Fatal(err)
79ca77f3
 	}
 
 	hostFile, err := os.Create(cpFullPath)
 	if err != nil {
dc944ea7
 		c.Fatal(err)
79ca77f3
 	}
 	defer hostFile.Close()
 	defer os.RemoveAll(cpTestPathParent)
 
 	fmt.Fprintf(hostFile, "%s", cpHostContents)
 
 	tmpdir, err := ioutil.TempDir("", "docker-integration")
 
 	if err != nil {
dc944ea7
 		c.Fatal(err)
79ca77f3
 	}
 
 	tmpname := filepath.Join(tmpdir, cpTestName)
 	defer os.RemoveAll(tmpdir)
 
 	path := cpFullPath
 
dc944ea7
 	_, _ = dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
79ca77f3
 
 	file, _ := os.Open(tmpname)
 	defer file.Close()
 
 	test, err := ioutil.ReadAll(file)
 	if err != nil {
dc944ea7
 		c.Fatal(err)
79ca77f3
 	}
 
 	if string(test) == cpHostContents {
dc944ea7
 		c.Errorf("output matched host file -- absolute path can escape container rootfs")
79ca77f3
 	}
 
 	if string(test) != cpContainerContents {
dc944ea7
 		c.Errorf("output doesn't match the input for absolute path")
79ca77f3
 	}
 
 }
5eef0a28
 
ff24a328
 // Test for #5619
 // Check that absolute symlinks are still relative to the container's rootfs
dc944ea7
 func (s *DockerSuite) TestCpAbsoluteSymlink(c *check.C) {
 	out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpFullPath+" container_path")
621b601b
 	if exitCode != 0 {
dc944ea7
 		c.Fatal("failed to create a container", out)
ff24a328
 	}
 
475c6531
 	cleanedContainerID := strings.TrimSpace(out)
ff24a328
 
dc944ea7
 	out, _ = dockerCmd(c, "wait", cleanedContainerID)
621b601b
 	if strings.TrimSpace(out) != "0" {
dc944ea7
 		c.Fatal("failed to set up container", out)
ff24a328
 	}
 
 	if err := os.MkdirAll(cpTestPath, os.ModeDir); err != nil {
dc944ea7
 		c.Fatal(err)
ff24a328
 	}
 
 	hostFile, err := os.Create(cpFullPath)
 	if err != nil {
dc944ea7
 		c.Fatal(err)
ff24a328
 	}
 	defer hostFile.Close()
 	defer os.RemoveAll(cpTestPathParent)
 
 	fmt.Fprintf(hostFile, "%s", cpHostContents)
 
 	tmpdir, err := ioutil.TempDir("", "docker-integration")
 
 	if err != nil {
dc944ea7
 		c.Fatal(err)
ff24a328
 	}
 
 	tmpname := filepath.Join(tmpdir, cpTestName)
 	defer os.RemoveAll(tmpdir)
 
c5b312dc
 	path := path.Join("/", "container_path")
ff24a328
 
dc944ea7
 	_, _ = dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
ff24a328
 
 	file, _ := os.Open(tmpname)
 	defer file.Close()
 
 	test, err := ioutil.ReadAll(file)
 	if err != nil {
dc944ea7
 		c.Fatal(err)
ff24a328
 	}
 
 	if string(test) == cpHostContents {
dc944ea7
 		c.Errorf("output matched host file -- absolute symlink can escape container rootfs")
ff24a328
 	}
 
 	if string(test) != cpContainerContents {
dc944ea7
 		c.Errorf("output doesn't match the input for absolute symlink")
ff24a328
 	}
 
 }
 
 // Test for #5619
 // Check that symlinks which are part of the resource path are still relative to the container's rootfs
dc944ea7
 func (s *DockerSuite) TestCpSymlinkComponent(c *check.C) {
 	out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpTestPath+" container_path")
621b601b
 	if exitCode != 0 {
dc944ea7
 		c.Fatal("failed to create a container", out)
ff24a328
 	}
 
475c6531
 	cleanedContainerID := strings.TrimSpace(out)
ff24a328
 
dc944ea7
 	out, _ = dockerCmd(c, "wait", cleanedContainerID)
621b601b
 	if strings.TrimSpace(out) != "0" {
dc944ea7
 		c.Fatal("failed to set up container", out)
ff24a328
 	}
 
 	if err := os.MkdirAll(cpTestPath, os.ModeDir); err != nil {
dc944ea7
 		c.Fatal(err)
ff24a328
 	}
 
 	hostFile, err := os.Create(cpFullPath)
 	if err != nil {
dc944ea7
 		c.Fatal(err)
ff24a328
 	}
 	defer hostFile.Close()
 	defer os.RemoveAll(cpTestPathParent)
 
 	fmt.Fprintf(hostFile, "%s", cpHostContents)
 
 	tmpdir, err := ioutil.TempDir("", "docker-integration")
 
 	if err != nil {
dc944ea7
 		c.Fatal(err)
ff24a328
 	}
 
 	tmpname := filepath.Join(tmpdir, cpTestName)
 	defer os.RemoveAll(tmpdir)
 
c5b312dc
 	path := path.Join("/", "container_path", cpTestName)
ff24a328
 
dc944ea7
 	_, _ = dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
ff24a328
 
 	file, _ := os.Open(tmpname)
 	defer file.Close()
 
 	test, err := ioutil.ReadAll(file)
 	if err != nil {
dc944ea7
 		c.Fatal(err)
ff24a328
 	}
 
 	if string(test) == cpHostContents {
dc944ea7
 		c.Errorf("output matched host file -- symlink path component can escape container rootfs")
ff24a328
 	}
 
 	if string(test) != cpContainerContents {
dc944ea7
 		c.Errorf("output doesn't match the input for symlink path component")
ff24a328
 	}
 
 }
 
5eef0a28
 // Check that cp with unprivileged user doesn't return any error
dc944ea7
 func (s *DockerSuite) TestCpUnprivilegedUser(c *check.C) {
 	testRequires(c, UnixCli) // uses chmod/su: not available on windows
492a58f0
 
dc944ea7
 	out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "touch "+cpTestName)
621b601b
 	if exitCode != 0 {
dc944ea7
 		c.Fatal("failed to create a container", out)
5eef0a28
 	}
 
475c6531
 	cleanedContainerID := strings.TrimSpace(out)
5eef0a28
 
dc944ea7
 	out, _ = dockerCmd(c, "wait", cleanedContainerID)
621b601b
 	if strings.TrimSpace(out) != "0" {
dc944ea7
 		c.Fatal("failed to set up container", out)
5eef0a28
 	}
 
 	tmpdir, err := ioutil.TempDir("", "docker-integration")
 	if err != nil {
dc944ea7
 		c.Fatal(err)
5eef0a28
 	}
 
 	defer os.RemoveAll(tmpdir)
 
 	if err = os.Chmod(tmpdir, 0777); err != nil {
dc944ea7
 		c.Fatal(err)
5eef0a28
 	}
 
 	path := cpTestName
 
 	_, _, err = runCommandWithOutput(exec.Command("su", "unprivilegeduser", "-c", dockerBinary+" cp "+cleanedContainerID+":"+path+" "+tmpdir))
 	if err != nil {
dc944ea7
 		c.Fatalf("couldn't copy with unprivileged user: %s:%s %s", cleanedContainerID, path, err)
5eef0a28
 	}
 
 }
ef98fe07
 
dc944ea7
 func (s *DockerSuite) TestCpSpecialFiles(c *check.C) {
 	testRequires(c, SameHostDaemon)
8bc330d8
 
 	outDir, err := ioutil.TempDir("", "cp-test-special-files")
 	if err != nil {
dc944ea7
 		c.Fatal(err)
8bc330d8
 	}
 	defer os.RemoveAll(outDir)
 
dc944ea7
 	out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "touch /foo")
621b601b
 	if exitCode != 0 {
dc944ea7
 		c.Fatal("failed to create a container", out)
8bc330d8
 	}
 
475c6531
 	cleanedContainerID := strings.TrimSpace(out)
8bc330d8
 
dc944ea7
 	out, _ = dockerCmd(c, "wait", cleanedContainerID)
621b601b
 	if strings.TrimSpace(out) != "0" {
dc944ea7
 		c.Fatal("failed to set up container", out)
8bc330d8
 	}
 
 	// Copy actual /etc/resolv.conf
dc944ea7
 	_, _ = dockerCmd(c, "cp", cleanedContainerID+":/etc/resolv.conf", outDir)
8bc330d8
 
 	expected, err := ioutil.ReadFile("/var/lib/docker/containers/" + cleanedContainerID + "/resolv.conf")
 	actual, err := ioutil.ReadFile(outDir + "/resolv.conf")
 
 	if !bytes.Equal(actual, expected) {
dc944ea7
 		c.Fatalf("Expected copied file to be duplicate of the container resolvconf")
8bc330d8
 	}
 
 	// Copy actual /etc/hosts
dc944ea7
 	_, _ = dockerCmd(c, "cp", cleanedContainerID+":/etc/hosts", outDir)
8bc330d8
 
 	expected, err = ioutil.ReadFile("/var/lib/docker/containers/" + cleanedContainerID + "/hosts")
 	actual, err = ioutil.ReadFile(outDir + "/hosts")
 
 	if !bytes.Equal(actual, expected) {
dc944ea7
 		c.Fatalf("Expected copied file to be duplicate of the container hosts")
8bc330d8
 	}
 
 	// Copy actual /etc/resolv.conf
dc944ea7
 	_, _ = dockerCmd(c, "cp", cleanedContainerID+":/etc/hostname", outDir)
8bc330d8
 
 	expected, err = ioutil.ReadFile("/var/lib/docker/containers/" + cleanedContainerID + "/hostname")
 	actual, err = ioutil.ReadFile(outDir + "/hostname")
 
 	if !bytes.Equal(actual, expected) {
dc944ea7
 		c.Fatalf("Expected copied file to be duplicate of the container resolvconf")
8bc330d8
 	}
 
 }
 
dc944ea7
 func (s *DockerSuite) TestCpVolumePath(c *check.C) {
 	testRequires(c, SameHostDaemon)
b686b65c
 
ef98fe07
 	tmpDir, err := ioutil.TempDir("", "cp-test-volumepath")
 	if err != nil {
dc944ea7
 		c.Fatal(err)
ef98fe07
 	}
 	defer os.RemoveAll(tmpDir)
 	outDir, err := ioutil.TempDir("", "cp-test-volumepath-out")
 	if err != nil {
dc944ea7
 		c.Fatal(err)
ef98fe07
 	}
 	defer os.RemoveAll(outDir)
 	_, err = os.Create(tmpDir + "/test")
 	if err != nil {
dc944ea7
 		c.Fatal(err)
ef98fe07
 	}
 
dc944ea7
 	out, exitCode := dockerCmd(c, "run", "-d", "-v", "/foo", "-v", tmpDir+"/test:/test", "-v", tmpDir+":/baz", "busybox", "/bin/sh", "-c", "touch /foo/bar")
621b601b
 	if exitCode != 0 {
dc944ea7
 		c.Fatal("failed to create a container", out)
ef98fe07
 	}
 
475c6531
 	cleanedContainerID := strings.TrimSpace(out)
ef98fe07
 
dc944ea7
 	out, _ = dockerCmd(c, "wait", cleanedContainerID)
621b601b
 	if strings.TrimSpace(out) != "0" {
dc944ea7
 		c.Fatal("failed to set up container", out)
ef98fe07
 	}
 
 	// Copy actual volume path
dc944ea7
 	_, _ = dockerCmd(c, "cp", cleanedContainerID+":/foo", outDir)
621b601b
 
ef98fe07
 	stat, err := os.Stat(outDir + "/foo")
 	if err != nil {
dc944ea7
 		c.Fatal(err)
ef98fe07
 	}
 	if !stat.IsDir() {
dc944ea7
 		c.Fatal("expected copied content to be dir")
ef98fe07
 	}
 	stat, err = os.Stat(outDir + "/foo/bar")
 	if err != nil {
dc944ea7
 		c.Fatal(err)
ef98fe07
 	}
 	if stat.IsDir() {
dc944ea7
 		c.Fatal("Expected file `bar` to be a file")
ef98fe07
 	}
 
 	// Copy file nested in volume
dc944ea7
 	_, _ = dockerCmd(c, "cp", cleanedContainerID+":/foo/bar", outDir)
621b601b
 
ef98fe07
 	stat, err = os.Stat(outDir + "/bar")
 	if err != nil {
dc944ea7
 		c.Fatal(err)
ef98fe07
 	}
 	if stat.IsDir() {
dc944ea7
 		c.Fatal("Expected file `bar` to be a file")
ef98fe07
 	}
 
 	// Copy Bind-mounted dir
dc944ea7
 	_, _ = dockerCmd(c, "cp", cleanedContainerID+":/baz", outDir)
ef98fe07
 	stat, err = os.Stat(outDir + "/baz")
 	if err != nil {
dc944ea7
 		c.Fatal(err)
ef98fe07
 	}
 	if !stat.IsDir() {
dc944ea7
 		c.Fatal("Expected `baz` to be a dir")
ef98fe07
 	}
 
 	// Copy file nested in bind-mounted dir
dc944ea7
 	_, _ = dockerCmd(c, "cp", cleanedContainerID+":/baz/test", outDir)
ef98fe07
 	fb, err := ioutil.ReadFile(outDir + "/baz/test")
 	if err != nil {
dc944ea7
 		c.Fatal(err)
ef98fe07
 	}
 	fb2, err := ioutil.ReadFile(tmpDir + "/test")
 	if err != nil {
dc944ea7
 		c.Fatal(err)
ef98fe07
 	}
 	if !bytes.Equal(fb, fb2) {
dc944ea7
 		c.Fatalf("Expected copied file to be duplicate of bind-mounted file")
ef98fe07
 	}
 
 	// Copy bind-mounted file
dc944ea7
 	_, _ = dockerCmd(c, "cp", cleanedContainerID+":/test", outDir)
ef98fe07
 	fb, err = ioutil.ReadFile(outDir + "/test")
 	if err != nil {
dc944ea7
 		c.Fatal(err)
ef98fe07
 	}
 	fb2, err = ioutil.ReadFile(tmpDir + "/test")
 	if err != nil {
dc944ea7
 		c.Fatal(err)
ef98fe07
 	}
 	if !bytes.Equal(fb, fb2) {
dc944ea7
 		c.Fatalf("Expected copied file to be duplicate of bind-mounted file")
ef98fe07
 	}
 
 }
be5bfbe2
 
dc944ea7
 func (s *DockerSuite) TestCpToDot(c *check.C) {
 	out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /test")
621b601b
 	if exitCode != 0 {
dc944ea7
 		c.Fatal("failed to create a container", out)
be5bfbe2
 	}
 
475c6531
 	cleanedContainerID := strings.TrimSpace(out)
be5bfbe2
 
dc944ea7
 	out, _ = dockerCmd(c, "wait", cleanedContainerID)
621b601b
 	if strings.TrimSpace(out) != "0" {
dc944ea7
 		c.Fatal("failed to set up container", out)
be5bfbe2
 	}
 
 	tmpdir, err := ioutil.TempDir("", "docker-integration")
 	if err != nil {
dc944ea7
 		c.Fatal(err)
be5bfbe2
 	}
 	defer os.RemoveAll(tmpdir)
 	cwd, err := os.Getwd()
 	if err != nil {
dc944ea7
 		c.Fatal(err)
be5bfbe2
 	}
 	defer os.Chdir(cwd)
 	if err := os.Chdir(tmpdir); err != nil {
dc944ea7
 		c.Fatal(err)
be5bfbe2
 	}
dc944ea7
 	_, _ = dockerCmd(c, "cp", cleanedContainerID+":/test", ".")
be5bfbe2
 	content, err := ioutil.ReadFile("./test")
 	if string(content) != "lololol\n" {
dc944ea7
 		c.Fatalf("Wrong content in copied file %q, should be %q", content, "lololol\n")
be5bfbe2
 	}
 }
f3d96e81
 
dc944ea7
 func (s *DockerSuite) TestCpToStdout(c *check.C) {
 	out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /test")
621b601b
 	if exitCode != 0 {
dc944ea7
 		c.Fatalf("failed to create a container:%s\n", out)
f3d96e81
 	}
 
475c6531
 	cID := strings.TrimSpace(out)
f3d96e81
 
dc944ea7
 	out, _ = dockerCmd(c, "wait", cID)
621b601b
 	if strings.TrimSpace(out) != "0" {
dc944ea7
 		c.Fatalf("failed to set up container:%s\n", out)
f3d96e81
 	}
 
621b601b
 	out, _, err := runCommandPipelineWithOutput(
f3d96e81
 		exec.Command(dockerBinary, "cp", cID+":/test", "-"),
 		exec.Command("tar", "-vtf", "-"))
621b601b
 
f3d96e81
 	if err != nil {
dc944ea7
 		c.Fatalf("Failed to run commands: %s", err)
f3d96e81
 	}
 
 	if !strings.Contains(out, "test") || !strings.Contains(out, "-rw") {
dc944ea7
 		c.Fatalf("Missing file from tar TOC:\n%s", out)
f3d96e81
 	}
 }
50372973
 
dc944ea7
 func (s *DockerSuite) TestCpNameHasColon(c *check.C) {
 	testRequires(c, SameHostDaemon)
50372973
 
dc944ea7
 	out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /te:s:t")
621b601b
 	if exitCode != 0 {
dc944ea7
 		c.Fatal("failed to create a container", out)
50372973
 	}
 
 	cleanedContainerID := strings.TrimSpace(out)
 
dc944ea7
 	out, _ = dockerCmd(c, "wait", cleanedContainerID)
621b601b
 	if strings.TrimSpace(out) != "0" {
dc944ea7
 		c.Fatal("failed to set up container", out)
50372973
 	}
 
 	tmpdir, err := ioutil.TempDir("", "docker-integration")
 	if err != nil {
dc944ea7
 		c.Fatal(err)
50372973
 	}
 	defer os.RemoveAll(tmpdir)
dc944ea7
 	_, _ = dockerCmd(c, "cp", cleanedContainerID+":/te:s:t", tmpdir)
50372973
 	content, err := ioutil.ReadFile(tmpdir + "/te:s:t")
 	if string(content) != "lololol\n" {
dc944ea7
 		c.Fatalf("Wrong content in copied file %q, should be %q", content, "lololol\n")
50372973
 	}
 }
04f99a6c
 
 func (s *DockerSuite) TestCopyAndRestart(c *check.C) {
 	expectedMsg := "hello"
 	out, err := exec.Command(dockerBinary, "run", "-d", "busybox", "echo", expectedMsg).CombinedOutput()
 	if err != nil {
 		c.Fatal(string(out), err)
 	}
 	id := strings.TrimSpace(string(out))
 
 	if out, err = exec.Command(dockerBinary, "wait", id).CombinedOutput(); err != nil {
 		c.Fatalf("unable to wait for container: %s", err)
 	}
 
 	status := strings.TrimSpace(string(out))
 	if status != "0" {
 		c.Fatalf("container exited with status %s", status)
 	}
 
 	tmpDir, err := ioutil.TempDir("", "test-docker-restart-after-copy-")
 	if err != nil {
 		c.Fatalf("unable to make temporary directory: %s", err)
 	}
 	defer os.RemoveAll(tmpDir)
 
 	if _, err = exec.Command(dockerBinary, "cp", fmt.Sprintf("%s:/etc/issue", id), tmpDir).CombinedOutput(); err != nil {
 		c.Fatalf("unable to copy from busybox container: %s", err)
 	}
 
 	if out, err = exec.Command(dockerBinary, "start", "-a", id).CombinedOutput(); err != nil {
 		c.Fatalf("unable to start busybox container after copy: %s - %s", err, out)
 	}
 
 	msg := strings.TrimSpace(string(out))
 	if msg != expectedMsg {
 		c.Fatalf("expected %q but got %q", expectedMsg, msg)
 	}
 }