{"action":"created","comment":{"url":"https://api.github.com/repos/docker/docker/pulls/comments/24603271","id":24603271,"diff_hunk":"@@ -0,0 +1,218 @@\n+package client\n+\n+import (\n+\t\"encoding/json\"\n+\t\"fmt\"\n+\t\"net/url\"\n+\t\"os\"\n+\t\"path/filepath\"\n+\t\"strings\"\n+\t\"time\"\n+\n+\t\"github.com/docker/docker/pkg/archive\"\n+)\n+\n+type copyDirection int\n+\n+const (\n+\tfromContainer copyDirection = (1 << iota)\n+\ttoContainer\n+\tacrossContainers = fromContainer | toContainer\n+)\n+\n+// CmdCp handles copying files or directories to/from/across containers.\n+func (cli *DockerCli) CmdCp(args ...string) error {\n+\tcmd := cli.Subcmd(\"cp\", \"[SRC_CONTAINER:]SRC_PATH [DST_CONTAINER:]DST_PATH\", \"Copy files between containers or a local path\", true)\n+\tif err := cmd.Parse(args); err != nil {\n+\t\treturn nil\n+\t}\n+\n+\tif cmd.NArg() != 2 {\n+\t\tcmd.Usage()\n+\t\treturn nil\n+\t}\n+\n+\tvar (\n+\t\tsrcPath      = cmd.Arg(0)\n+\t\tdstPath      = cmd.Arg(1)\n+\t\tsrcContainer string\n+\t\tdstContainer string\n+\t\tdirection    copyDirection\n+\t)\n+\n+\tif strings.Contains(srcPath, \":\") {\n+\t\t// Copy from a container.\n+\t\tdirection |= fromContainer\n+\t\tsrcInfo := strings.SplitN(srcPath, \":\", 2)\n+\t\tsrcContainer, srcPath = srcInfo[0], srcInfo[1]\n+\t}\n+\n+\tif strings.Contains(dstPath, \":\") {\n+\t\t// Copy to a container.\n+\t\tdirection |= toContainer\n+\t\tdstInfo := strings.SplitN(dstPath, \":\", 2)\n+\t\tdstContainer, dstPath = dstInfo[0], dstInfo[1]\n+\t}\n+\n+\tswitch direction {\n+\tcase fromContainer:\n+\t\t// Copy from a container to a local path.\n+\t\treturn cli.copyFromContainer(srcContainer, srcPath, dstPath)\n+\tcase toContainer:\n+\t\t// Copy from a local path to a container.\n+\t\treturn cli.copyToContainer(srcPath, dstContainer, dstPath)\n+\tcase acrossContainers:\n+\t\t// Copy from one container to another.\n+\t\treturn cli.copyAcrossContainers(srcContainer, srcPath, dstContainer, dstPath)\n+\tdefault:\n+\t\t// User didn't specify any container.\n+\t\treturn fmt.Errorf(\"error: Wrong path format. Must specify a source and/or destination container\")\n+\t}\n+}\n+\n+type containerPathStat struct {\n+\tName    string      `json:\"name\"`\n+\tAbsPath string      `json:\"absPath\"`\n+\tSize    int64       `json:\"size\"`\n+\tMode    os.FileMode `json:\"mode\"`\n+\tMtime   time.Time   `json:\"mtime\"`\n+}\n+\n+func (cli *DockerCli) statContainerPath(containerName, path string) (containerPathStat, error) {\n+\tvar stat containerPathStat\n+\n+\tquery := make(url.Values, 1)\n+\tquery.Set(\"path\", path)\n+\n+\turlStr := fmt.Sprintf(\"/containers/%s/stat-path?%s\", containerName, query.Encode())","path":"api/client/copy.go","position":87,"original_position":87,"commit_id":"fd1a3b640e69ea2d4e4145eab2755d27052fe189","original_commit_id":"fd1a3b640e69ea2d4e4145eab2755d27052fe189","user":{"login":"jlhawn","id":1441929,"avatar_url":"https://avatars.githubusercontent.com/u/1441929?v=3","gravatar_id":"","url":"https://api.github.com/users/jlhawn","html_url":"https://github.com/jlhawn","followers_url":"https://api.github.com/users/jlhawn/followers","following_url":"https://api.github.com/users/jlhawn/following{/other_user}","gists_url":"https://api.github.com/users/jlhawn/gists{/gist_id}","starred_url":"https://api.github.com/users/jlhawn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jlhawn/subscriptions","organizations_url":"https://api.github.com/users/jlhawn/orgs","repos_url":"https://api.github.com/users/jlhawn/repos","events_url":"https://api.github.com/users/jlhawn/events{/privacy}","received_events_url":"https://api.github.com/users/jlhawn/received_events","type":"User","site_admin":false},"body":"Then the only question would be: what is this header going to look like?","created_at":"2015-02-12T18:15:42Z","updated_at":"2015-02-12T18:15:42Z","html_url":"https://github.com/docker/docker/pull/10198#discussion_r24603271","pull_request_url":"https://api.github.com/repos/docker/docker/pulls/10198","_links":{"self":{"href":"https://api.github.com/repos/docker/docker/pulls/comments/24603271"},"html":{"href":"https://github.com/docker/docker/pull/10198#discussion_r24603271"},"pull_request":{"href":"https://api.github.com/repos/docker/docker/pulls/10198"}}},"pull_request":{"url":"https://api.github.com/repos/docker/docker/pulls/10198","id":27636039,"html_url":"https://github.com/docker/docker/pull/10198","diff_url":"https://github.com/docker/docker/pull/10198.diff","patch_url":"https://github.com/docker/docker/pull/10198.patch","issue_url":"https://api.github.com/repos/docker/docker/issues/10198","number":10198,"state":"open","locked":false,"title":"docker cp to, from, and between containers","user":{"login":"jlhawn","id":1441929,"avatar_url":"https://avatars.githubusercontent.com/u/1441929?v=3","gravatar_id":"","url":"https://api.github.com/users/jlhawn","html_url":"https://github.com/jlhawn","followers_url":"https://api.github.com/users/jlhawn/followers","following_url":"https://api.github.com/users/jlhawn/following{/other_user}","gists_url":"https://api.github.com/users/jlhawn/gists{/gist_id}","starred_url":"https://api.github.com/users/jlhawn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jlhawn/subscriptions","organizations_url":"https://api.github.com/users/jlhawn/orgs","repos_url":"https://api.github.com/users/jlhawn/repos","events_url":"https://api.github.com/users/jlhawn/events{/privacy}","received_events_url":"https://api.github.com/users/jlhawn/received_events","type":"User","site_admin":false},"body":"**please check the first commit with documentation changes for details**\r\n\r\nfixes #5846","created_at":"2015-01-19T21:12:54Z","updated_at":"2015-02-12T18:15:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ad74d5c5d1f83ce596e9836d52ef4dd25fe6399c","assignee":null,"milestone":{"url":"https://api.github.com/repos/docker/docker/milestones/37","labels_url":"https://api.github.com/repos/docker/docker/milestones/37/labels","id":952335,"number":37,"title":"1.6.0","description":"","creator":{"login":"crosbymichael","id":749551,"avatar_url":"https://avatars.githubusercontent.com/u/749551?v=3","gravatar_id":"","url":"https://api.github.com/users/crosbymichael","html_url":"https://github.com/crosbymichael","followers_url":"https://api.github.com/users/crosbymichael/followers","following_url":"https://api.github.com/users/crosbymichael/following{/other_user}","gists_url":"https://api.github.com/users/crosbymichael/gists{/gist_id}","starred_url":"https://api.github.com/users/crosbymichael/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crosbymichael/subscriptions","organizations_url":"https://api.github.com/users/crosbymichael/orgs","repos_url":"https://api.github.com/users/crosbymichael/repos","events_url":"https://api.github.com/users/crosbymichael/events{/privacy}","received_events_url":"https://api.github.com/users/crosbymichael/received_events","type":"User","site_admin":false},"open_issues":14,"closed_issues":7,"state":"open","created_at":"2015-01-26T23:40:13Z","updated_at":"2015-02-12T03:17:51Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/docker/docker/pulls/10198/commits","review_comments_url":"https://api.github.com/repos/docker/docker/pulls/10198/comments","review_comment_url":"https://api.github.com/repos/docker/docker/pulls/comments/{number}","comments_url":"https://api.github.com/repos/docker/docker/issues/10198/comments","statuses_url":"https://api.github.com/repos/docker/docker/statuses/fd1a3b640e69ea2d4e4145eab2755d27052fe189","head":{"label":"jlhawn:new_docker_cp","ref":"new_docker_cp","sha":"fd1a3b640e69ea2d4e4145eab2755d27052fe189","user":{"login":"jlhawn","id":1441929,"avatar_url":"https://avatars.githubusercontent.com/u/1441929?v=3","gravatar_id":"","url":"https://api.github.com/users/jlhawn","html_url":"https://github.com/jlhawn","followers_url":"https://api.github.com/users/jlhawn/followers","following_url":"https://api.github.com/users/jlhawn/following{/other_user}","gists_url":"https://api.github.com/users/jlhawn/gists{/gist_id}","starred_url":"https://api.github.com/users/jlhawn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jlhawn/subscriptions","organizations_url":"https://api.github.com/users/jlhawn/orgs","repos_url":"https://api.github.com/users/jlhawn/repos","events_url":"https://api.github.com/users/jlhawn/events{/privacy}","received_events_url":"https://api.github.com/users/jlhawn/received_events","type":"User","site_admin":false},"repo":{"id":14341765,"name":"docker","full_name":"jlhawn/docker","owner":{"login":"jlhawn","id":1441929,"avatar_url":"https://avatars.githubusercontent.com/u/1441929?v=3","gravatar_id":"","url":"https://api.github.com/users/jlhawn","html_url":"https://github.com/jlhawn","followers_url":"https://api.github.com/users/jlhawn/followers","following_url":"https://api.github.com/users/jlhawn/following{/other_user}","gists_url":"https://api.github.com/users/jlhawn/gists{/gist_id}","starred_url":"https://api.github.com/users/jlhawn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jlhawn/subscriptions","organizations_url":"https://api.github.com/users/jlhawn/orgs","repos_url":"https://api.github.com/users/jlhawn/repos","events_url":"https://api.github.com/users/jlhawn/events{/privacy}","received_events_url":"https://api.github.com/users/jlhawn/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jlhawn/docker","description":"Docker - the open-source application container engine","fork":true,"url":"https://api.github.com/repos/jlhawn/docker","forks_url":"https://api.github.com/repos/jlhawn/docker/forks","keys_url":"https://api.github.com/repos/jlhawn/docker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jlhawn/docker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jlhawn/docker/teams","hooks_url":"https://api.github.com/repos/jlhawn/docker/hooks","issue_events_url":"https://api.github.com/repos/jlhawn/docker/issues/events{/number}","events_url":"https://api.github.com/repos/jlhawn/docker/events","assignees_url":"https://api.github.com/repos/jlhawn/docker/assignees{/user}","branches_url":"https://api.github.com/repos/jlhawn/docker/branches{/branch}","tags_url":"https://api.github.com/repos/jlhawn/docker/tags","blobs_url":"https://api.github.com/repos/jlhawn/docker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jlhawn/docker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jlhawn/docker/git/refs{/sha}","trees_url":"https://api.github.com/repos/jlhawn/docker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jlhawn/docker/statuses/{sha}","languages_url":"https://api.github.com/repos/jlhawn/docker/languages","stargazers_url":"https://api.github.com/repos/jlhawn/docker/stargazers","contributors_url":"https://api.github.com/repos/jlhawn/docker/contributors","subscribers_url":"https://api.github.com/repos/jlhawn/docker/subscribers","subscription_url":"https://api.github.com/repos/jlhawn/docker/subscription","commits_url":"https://api.github.com/repos/jlhawn/docker/commits{/sha}","git_commits_url":"https://api.github.com/repos/jlhawn/docker/git/commits{/sha}","comments_url":"https://api.github.com/repos/jlhawn/docker/comments{/number}","issue_comment_url":"https://api.github.com/repos/jlhawn/docker/issues/comments/{number}","contents_url":"https://api.github.com/repos/jlhawn/docker/contents/{+path}","compare_url":"https://api.github.com/repos/jlhawn/docker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jlhawn/docker/merges","archive_url":"https://api.github.com/repos/jlhawn/docker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jlhawn/docker/downloads","issues_url":"https://api.github.com/repos/jlhawn/docker/issues{/number}","pulls_url":"https://api.github.com/repos/jlhawn/docker/pulls{/number}","milestones_url":"https://api.github.com/repos/jlhawn/docker/milestones{/number}","notifications_url":"https://api.github.com/repos/jlhawn/docker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jlhawn/docker/labels{/name}","releases_url":"https://api.github.com/repos/jlhawn/docker/releases{/id}","created_at":"2013-11-12T18:50:12Z","updated_at":"2015-02-02T19:07:23Z","pushed_at":"2015-02-12T04:22:32Z","git_url":"git://github.com/jlhawn/docker.git","ssh_url":"git@github.com:jlhawn/docker.git","clone_url":"https://github.com/jlhawn/docker.git","svn_url":"https://github.com/jlhawn/docker","homepage":"http://www.docker.io","size":42128,"stargazers_count":5,"watchers_count":5,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":5,"default_branch":"master"}},"base":{"label":"docker:master","ref":"master","sha":"f4749acad48f03454c951081a0a3f0149a23e260","user":{"login":"docker","id":5429470,"avatar_url":"https://avatars.githubusercontent.com/u/5429470?v=3","gravatar_id":"","url":"https://api.github.com/users/docker","html_url":"https://github.com/docker","followers_url":"https://api.github.com/users/docker/followers","following_url":"https://api.github.com/users/docker/following{/other_user}","gists_url":"https://api.github.com/users/docker/gists{/gist_id}","starred_url":"https://api.github.com/users/docker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/docker/subscriptions","organizations_url":"https://api.github.com/users/docker/orgs","repos_url":"https://api.github.com/users/docker/repos","events_url":"https://api.github.com/users/docker/events{/privacy}","received_events_url":"https://api.github.com/users/docker/received_events","type":"Organization","site_admin":false},"repo":{"id":7691631,"name":"docker","full_name":"docker/docker","owner":{"login":"docker","id":5429470,"avatar_url":"https://avatars.githubusercontent.com/u/5429470?v=3","gravatar_id":"","url":"https://api.github.com/users/docker","html_url":"https://github.com/docker","followers_url":"https://api.github.com/users/docker/followers","following_url":"https://api.github.com/users/docker/following{/other_user}","gists_url":"https://api.github.com/users/docker/gists{/gist_id}","starred_url":"https://api.github.com/users/docker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/docker/subscriptions","organizations_url":"https://api.github.com/users/docker/orgs","repos_url":"https://api.github.com/users/docker/repos","events_url":"https://api.github.com/users/docker/events{/privacy}","received_events_url":"https://api.github.com/users/docker/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/docker/docker","description":"Docker - the open-source application container engine","fork":false,"url":"https://api.github.com/repos/docker/docker","forks_url":"https://api.github.com/repos/docker/docker/forks","keys_url":"https://api.github.com/repos/docker/docker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/docker/docker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/docker/docker/teams","hooks_url":"https://api.github.com/repos/docker/docker/hooks","issue_events_url":"https://api.github.com/repos/docker/docker/issues/events{/number}","events_url":"https://api.github.com/repos/docker/docker/events","assignees_url":"https://api.github.com/repos/docker/docker/assignees{/user}","branches_url":"https://api.github.com/repos/docker/docker/branches{/branch}","tags_url":"https://api.github.com/repos/docker/docker/tags","blobs_url":"https://api.github.com/repos/docker/docker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/docker/docker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/docker/docker/git/refs{/sha}","trees_url":"https://api.github.com/repos/docker/docker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/docker/docker/statuses/{sha}","languages_url":"https://api.github.com/repos/docker/docker/languages","stargazers_url":"https://api.github.com/repos/docker/docker/stargazers","contributors_url":"https://api.github.com/repos/docker/docker/contributors","subscribers_url":"https://api.github.com/repos/docker/docker/subscribers","subscription_url":"https://api.github.com/repos/docker/docker/subscription","commits_url":"https://api.github.com/repos/docker/docker/commits{/sha}","git_commits_url":"https://api.github.com/repos/docker/docker/git/commits{/sha}","comments_url":"https://api.github.com/repos/docker/docker/comments{/number}","issue_comment_url":"https://api.github.com/repos/docker/docker/issues/comments/{number}","contents_url":"https://api.github.com/repos/docker/docker/contents/{+path}","compare_url":"https://api.github.com/repos/docker/docker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/docker/docker/merges","archive_url":"https://api.github.com/repos/docker/docker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/docker/docker/downloads","issues_url":"https://api.github.com/repos/docker/docker/issues{/number}","pulls_url":"https://api.github.com/repos/docker/docker/pulls{/number}","milestones_url":"https://api.github.com/repos/docker/docker/milestones{/number}","notifications_url":"https://api.github.com/repos/docker/docker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/docker/docker/labels{/name}","releases_url":"https://api.github.com/repos/docker/docker/releases{/id}","created_at":"2013-01-18T18:10:57Z","updated_at":"2015-02-12T17:07:20Z","pushed_at":"2015-02-11T19:01:29Z","git_url":"git://github.com/docker/docker.git","ssh_url":"git@github.com:docker/docker.git","clone_url":"https://github.com/docker/docker.git","svn_url":"https://github.com/docker/docker","homepage":"http://www.docker.com","size":135994,"stargazers_count":19130,"watchers_count":19130,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":3952,"mirror_url":null,"open_issues_count":1023,"forks":3952,"open_issues":1023,"watchers":19130,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/docker/docker/pulls/10198"},"html":{"href":"https://github.com/docker/docker/pull/10198"},"issue":{"href":"https://api.github.com/repos/docker/docker/issues/10198"},"comments":{"href":"https://api.github.com/repos/docker/docker/issues/10198/comments"},"review_comments":{"href":"https://api.github.com/repos/docker/docker/pulls/10198/comments"},"review_comment":{"href":"https://api.github.com/repos/docker/docker/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/docker/docker/pulls/10198/commits"},"statuses":{"href":"https://api.github.com/repos/docker/docker/statuses/fd1a3b640e69ea2d4e4145eab2755d27052fe189"}}}}