{"action":"created","comment":{"url":"https://api.github.com/repos/docker/docker/pulls/comments/31857467","id":31857467,"diff_hunk":"@@ -428,10 +427,125 @@ func (graph *Graph) Heads() (map[string]*image.Image, error) {\n \treturn heads, err\n }\n \n-func (graph *Graph) ImageRoot(id string) string {\n+func (graph *Graph) imageRoot(id string) string {\n \treturn filepath.Join(graph.Root, id)\n }\n \n-func (graph *Graph) Driver() graphdriver.Driver {\n-\treturn graph.driver\n+// storeImage stores file system layer data for the given image to the\n+// graph's storage driver. Image metadata is stored in a file\n+// at the specified root directory.\n+func (graph *Graph) storeImage(img *image.Image, layerData archive.ArchiveReader, root string) (err error) {\n+\t// Store the layer. If layerData is not nil, unpack it into the new layer\n+\tif layerData != nil {\n+\t\tif img.Size, err = graph.driver.ApplyDiff(img.ID, img.Parent, layerData); err != nil {\n+\t\t\treturn err\n+\t\t}\n+\t}\n+\n+\tif err := graph.saveSize(root, int(img.Size)); err != nil {\n+\t\treturn err\n+\t}\n+\n+\tf, err := os.OpenFile(jsonPath(root), os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.FileMode(0600))\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\n+\tdefer f.Close()\n+\n+\treturn json.NewEncoder(f).Encode(img)\n+}\n+\n+// loadImage fetches the image with the given id from the graph.\n+func (graph *Graph) loadImage(id string) (*image.Image, error) {\n+\troot := graph.imageRoot(id)\n+\n+\t// Open the JSON file to decode by streaming\n+\tjsonSource, err := os.Open(jsonPath(root))\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\tdefer jsonSource.Close()\n+\n+\timg := &image.Image{}\n+\tdec := json.NewDecoder(jsonSource)\n+\n+\t// Decode the JSON data\n+\tif err := dec.Decode(img); err != nil {\n+\t\treturn nil, err\n+\t}\n+\tif err := image.ValidateID(img.ID); err != nil {\n+\t\treturn nil, err\n+\t}\n+\n+\tif buf, err := ioutil.ReadFile(filepath.Join(root, \"layersize\")); err != nil {\n+\t\tif !os.IsNotExist(err) {\n+\t\t\treturn nil, err\n+\t\t}\n+\t\t// If the layersize file does not exist then set the size to a negative number\n+\t\t// because a layer size of 0 (zero) is valid\n+\t\timg.Size = -1\n+\t} else {\n+\t\t// Using Atoi here instead would temporarily convert the size to a machine\n+\t\t// dependent integer type, which causes images larger than 2^31 bytes to\n+\t\t// display negative sizes on 32-bit machines:\n+\t\tsize, err := strconv.ParseInt(string(buf), 10, 64)\n+\t\tif err != nil {\n+\t\t\treturn nil, err\n+\t\t}\n+\t\timg.Size = int64(size)\n+\t}\n+\n+\treturn img, nil\n+}\n+\n+// saveSize stores the `size` in the provided graph `img` directory `root`.\n+func (graph *Graph) saveSize(root string, size int) error {\n+\tif err := ioutil.WriteFile(filepath.Join(root, \"layersize\"), []byte(strconv.Itoa(size)), 0600); err != nil {\n+\t\treturn fmt.Errorf(\"Error storing image size in %s/layersize: %s\", root, err)\n+\t}\n+\treturn nil\n+}\n+\n+// SetCheckSum sets the checksum for the image layer to the provided value.\n+func (graph *Graph) SetCheckSum(id, checksum string) error {","path":"graph/graph.go","position":227,"original_position":227,"commit_id":"ea602948ba169e7d2d33f126674fd3ced4f077b7","original_commit_id":"317ccf7d6cc5a3277f12483e91c239078898fa20","user":{"login":"dmcgowan","id":169601,"avatar_url":"https://avatars.githubusercontent.com/u/169601?v=3","gravatar_id":"","url":"https://api.github.com/users/dmcgowan","html_url":"https://github.com/dmcgowan","followers_url":"https://api.github.com/users/dmcgowan/followers","following_url":"https://api.github.com/users/dmcgowan/following{/other_user}","gists_url":"https://api.github.com/users/dmcgowan/gists{/gist_id}","starred_url":"https://api.github.com/users/dmcgowan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmcgowan/subscriptions","organizations_url":"https://api.github.com/users/dmcgowan/orgs","repos_url":"https://api.github.com/users/dmcgowan/repos","events_url":"https://api.github.com/users/dmcgowan/events{/privacy}","received_events_url":"https://api.github.com/users/dmcgowan/received_events","type":"User","site_admin":false},"body":"GetCheckSum should also be made type safe as well. If it is expected GetCheckSum will return a valid Digest, then it will also need to return an error when there is no CheckSum.","created_at":"2015-06-05T22:36:13Z","updated_at":"2015-06-05T22:36:13Z","html_url":"https://github.com/docker/docker/pull/13773#discussion_r31857467","pull_request_url":"https://api.github.com/repos/docker/docker/pulls/13773","_links":{"self":{"href":"https://api.github.com/repos/docker/docker/pulls/comments/31857467"},"html":{"href":"https://github.com/docker/docker/pull/13773#discussion_r31857467"},"pull_request":{"href":"https://api.github.com/repos/docker/docker/pulls/13773"}}},"pull_request":{"url":"https://api.github.com/repos/docker/docker/pulls/13773","id":37057516,"html_url":"https://github.com/docker/docker/pull/13773","diff_url":"https://github.com/docker/docker/pull/13773.diff","patch_url":"https://github.com/docker/docker/pull/13773.patch","issue_url":"https://api.github.com/repos/docker/docker/issues/13773","number":13773,"state":"open","locked":false,"title":"refactor: separate graph from image","user":{"login":"dmcgowan","id":169601,"avatar_url":"https://avatars.githubusercontent.com/u/169601?v=3","gravatar_id":"","url":"https://api.github.com/users/dmcgowan","html_url":"https://github.com/dmcgowan","followers_url":"https://api.github.com/users/dmcgowan/followers","following_url":"https://api.github.com/users/dmcgowan/following{/other_user}","gists_url":"https://api.github.com/users/dmcgowan/gists{/gist_id}","starred_url":"https://api.github.com/users/dmcgowan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmcgowan/subscriptions","organizations_url":"https://api.github.com/users/dmcgowan/orgs","repos_url":"https://api.github.com/users/dmcgowan/repos","events_url":"https://api.github.com/users/dmcgowan/events{/privacy}","received_events_url":"https://api.github.com/users/dmcgowan/received_events","type":"User","site_admin":false},"body":"Move graph related functions in image to graph package.\r\nConsolidating graph functionality is the first step in refactoring graph into an image store model.\r\nSubsequent refactors will involve breaking up graph into multiple types with a strongly defined interface.\r\n","created_at":"2015-06-05T18:29:30Z","updated_at":"2015-06-05T22:36:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"603c1a2fb07fb55ed1d246e62f948febbb546bf9","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/docker/docker/pulls/13773/commits","review_comments_url":"https://api.github.com/repos/docker/docker/pulls/13773/comments","review_comment_url":"https://api.github.com/repos/docker/docker/pulls/comments{/number}","comments_url":"https://api.github.com/repos/docker/docker/issues/13773/comments","statuses_url":"https://api.github.com/repos/docker/docker/statuses/ea602948ba169e7d2d33f126674fd3ced4f077b7","head":{"label":"dmcgowan:refactor-1-image-graph-separation","ref":"refactor-1-image-graph-separation","sha":"ea602948ba169e7d2d33f126674fd3ced4f077b7","user":{"login":"dmcgowan","id":169601,"avatar_url":"https://avatars.githubusercontent.com/u/169601?v=3","gravatar_id":"","url":"https://api.github.com/users/dmcgowan","html_url":"https://github.com/dmcgowan","followers_url":"https://api.github.com/users/dmcgowan/followers","following_url":"https://api.github.com/users/dmcgowan/following{/other_user}","gists_url":"https://api.github.com/users/dmcgowan/gists{/gist_id}","starred_url":"https://api.github.com/users/dmcgowan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmcgowan/subscriptions","organizations_url":"https://api.github.com/users/dmcgowan/orgs","repos_url":"https://api.github.com/users/dmcgowan/repos","events_url":"https://api.github.com/users/dmcgowan/events{/privacy}","received_events_url":"https://api.github.com/users/dmcgowan/received_events","type":"User","site_admin":false},"repo":{"id":22739098,"name":"docker","full_name":"dmcgowan/docker","owner":{"login":"dmcgowan","id":169601,"avatar_url":"https://avatars.githubusercontent.com/u/169601?v=3","gravatar_id":"","url":"https://api.github.com/users/dmcgowan","html_url":"https://github.com/dmcgowan","followers_url":"https://api.github.com/users/dmcgowan/followers","following_url":"https://api.github.com/users/dmcgowan/following{/other_user}","gists_url":"https://api.github.com/users/dmcgowan/gists{/gist_id}","starred_url":"https://api.github.com/users/dmcgowan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmcgowan/subscriptions","organizations_url":"https://api.github.com/users/dmcgowan/orgs","repos_url":"https://api.github.com/users/dmcgowan/repos","events_url":"https://api.github.com/users/dmcgowan/events{/privacy}","received_events_url":"https://api.github.com/users/dmcgowan/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dmcgowan/docker","description":"Docker - the open-source application container engine","fork":true,"url":"https://api.github.com/repos/dmcgowan/docker","forks_url":"https://api.github.com/repos/dmcgowan/docker/forks","keys_url":"https://api.github.com/repos/dmcgowan/docker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dmcgowan/docker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dmcgowan/docker/teams","hooks_url":"https://api.github.com/repos/dmcgowan/docker/hooks","issue_events_url":"https://api.github.com/repos/dmcgowan/docker/issues/events{/number}","events_url":"https://api.github.com/repos/dmcgowan/docker/events","assignees_url":"https://api.github.com/repos/dmcgowan/docker/assignees{/user}","branches_url":"https://api.github.com/repos/dmcgowan/docker/branches{/branch}","tags_url":"https://api.github.com/repos/dmcgowan/docker/tags","blobs_url":"https://api.github.com/repos/dmcgowan/docker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dmcgowan/docker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dmcgowan/docker/git/refs{/sha}","trees_url":"https://api.github.com/repos/dmcgowan/docker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dmcgowan/docker/statuses/{sha}","languages_url":"https://api.github.com/repos/dmcgowan/docker/languages","stargazers_url":"https://api.github.com/repos/dmcgowan/docker/stargazers","contributors_url":"https://api.github.com/repos/dmcgowan/docker/contributors","subscribers_url":"https://api.github.com/repos/dmcgowan/docker/subscribers","subscription_url":"https://api.github.com/repos/dmcgowan/docker/subscription","commits_url":"https://api.github.com/repos/dmcgowan/docker/commits{/sha}","git_commits_url":"https://api.github.com/repos/dmcgowan/docker/git/commits{/sha}","comments_url":"https://api.github.com/repos/dmcgowan/docker/comments{/number}","issue_comment_url":"https://api.github.com/repos/dmcgowan/docker/issues/comments{/number}","contents_url":"https://api.github.com/repos/dmcgowan/docker/contents/{+path}","compare_url":"https://api.github.com/repos/dmcgowan/docker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dmcgowan/docker/merges","archive_url":"https://api.github.com/repos/dmcgowan/docker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dmcgowan/docker/downloads","issues_url":"https://api.github.com/repos/dmcgowan/docker/issues{/number}","pulls_url":"https://api.github.com/repos/dmcgowan/docker/pulls{/number}","milestones_url":"https://api.github.com/repos/dmcgowan/docker/milestones{/number}","notifications_url":"https://api.github.com/repos/dmcgowan/docker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dmcgowan/docker/labels{/name}","releases_url":"https://api.github.com/repos/dmcgowan/docker/releases{/id}","created_at":"2014-08-07T22:58:18Z","updated_at":"2015-03-16T21:29:55Z","pushed_at":"2015-06-05T22:32:39Z","git_url":"git://github.com/dmcgowan/docker.git","ssh_url":"git@github.com:dmcgowan/docker.git","clone_url":"https://github.com/dmcgowan/docker.git","svn_url":"https://github.com/dmcgowan/docker","homepage":"http://www.docker.com","size":60443,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":4,"forks":1,"open_issues":4,"watchers":0,"default_branch":"master"}},"base":{"label":"docker:master","ref":"master","sha":"7c64ed5c8c49d786d626f6a4704d868ae4662374","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-06-05T22:19:16Z","pushed_at":"2015-06-05T22:32:42Z","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":209330,"stargazers_count":22186,"watchers_count":22186,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5298,"mirror_url":null,"open_issues_count":1037,"forks":5298,"open_issues":1037,"watchers":22186,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/docker/docker/pulls/13773"},"html":{"href":"https://github.com/docker/docker/pull/13773"},"issue":{"href":"https://api.github.com/repos/docker/docker/issues/13773"},"comments":{"href":"https://api.github.com/repos/docker/docker/issues/13773/comments"},"review_comments":{"href":"https://api.github.com/repos/docker/docker/pulls/13773/comments"},"review_comment":{"href":"https://api.github.com/repos/docker/docker/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/docker/docker/pulls/13773/commits"},"statuses":{"href":"https://api.github.com/repos/docker/docker/statuses/ea602948ba169e7d2d33f126674fd3ced4f077b7"}}}}