{"action":"created","comment":{"url":"https://api.github.com/repos/appc/docker2aci/pulls/comments/36518837","id":36518837,"diff_hunk":"@@ -167,24 +166,39 @@ func SquashLayers(images []acirenderer.Image, aciRegistry acirenderer.ACIRegistr\n \t}\n \n \tsquashedFilename := getSquashedFilename(parsedDockerURL)\n-\tsquashedImagePath := path.Join(outputDir, squashedFilename)\n+\tsquashedImagePath := filepath.Join(outputDir, squashedFilename)\n \n-\tsquashedImageFile, err := os.Create(squashedImagePath)\n+\tsquashedTempFile, err := ioutil.TempFile(outputDir, \"docker2aci-squashedFile-\")\n \tif err != nil {\n \t\treturn \"\", err\n \t}\n-\tdefer squashedImageFile.Close()\n+\tdefer func() {\n+\t\terrClose := squashedTempFile.Close()\n+\t\tif err != nil {\n+\t\t\t// remove temp file on error\n+\t\t\terrRemove := os.Remove(squashedTempFile.Name())\n+\t\t\tif errRemove != nil {\n+\t\t\t\terr = errRemove","path":"lib/docker2aci.go","position":36,"original_position":36,"commit_id":"86920c3b9012a1721d55310d148dff002dd8b9e2","original_commit_id":"86920c3b9012a1721d55310d148dff002dd8b9e2","user":{"login":"iaguis","id":507354,"avatar_url":"https://avatars.githubusercontent.com/u/507354?v=3","gravatar_id":"","url":"https://api.github.com/users/iaguis","html_url":"https://github.com/iaguis","followers_url":"https://api.github.com/users/iaguis/followers","following_url":"https://api.github.com/users/iaguis/following{/other_user}","gists_url":"https://api.github.com/users/iaguis/gists{/gist_id}","starred_url":"https://api.github.com/users/iaguis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iaguis/subscriptions","organizations_url":"https://api.github.com/users/iaguis/orgs","repos_url":"https://api.github.com/users/iaguis/repos","events_url":"https://api.github.com/users/iaguis/events{/privacy}","received_events_url":"https://api.github.com/users/iaguis/received_events","type":"User","site_admin":false},"body":"I think it's important to not ignore the Close error on successful cases to avoid data corruption.\r\n\r\nHow about we remove the temp file on error ignoring the Remove errors so we don't mask the \"real\" one and we handle the close error if there was a successful execution?\r\n\r\n```\r\ndefer func() {\r\n\tif err == nil {\r\n\t\terr = squashedTempFile.Close()\r\n\t} else {\r\n\t\t// remove temp file on error\r\n\t\t// we ignore its error to not mask the real error\r\n\t\tos.Remove(squashedTempFile.Name())\r\n\t}\r\n}()\r\n```","created_at":"2015-08-07T13:37:46Z","updated_at":"2015-08-07T13:37:46Z","html_url":"https://github.com/appc/docker2aci/pull/76#discussion_r36518837","pull_request_url":"https://api.github.com/repos/appc/docker2aci/pulls/76","_links":{"self":{"href":"https://api.github.com/repos/appc/docker2aci/pulls/comments/36518837"},"html":{"href":"https://github.com/appc/docker2aci/pull/76#discussion_r36518837"},"pull_request":{"href":"https://api.github.com/repos/appc/docker2aci/pulls/76"}}},"pull_request":{"url":"https://api.github.com/repos/appc/docker2aci/pulls/76","id":41655847,"html_url":"https://github.com/appc/docker2aci/pull/76","diff_url":"https://github.com/appc/docker2aci/pull/76.diff","patch_url":"https://github.com/appc/docker2aci/pull/76.patch","issue_url":"https://api.github.com/repos/appc/docker2aci/issues/76","number":76,"state":"open","locked":false,"title":"lib: properly write squashed ACI to disk","user":{"login":"iaguis","id":507354,"avatar_url":"https://avatars.githubusercontent.com/u/507354?v=3","gravatar_id":"","url":"https://api.github.com/users/iaguis","html_url":"https://github.com/iaguis","followers_url":"https://api.github.com/users/iaguis/followers","following_url":"https://api.github.com/users/iaguis/following{/other_user}","gists_url":"https://api.github.com/users/iaguis/gists{/gist_id}","starred_url":"https://api.github.com/users/iaguis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iaguis/subscriptions","organizations_url":"https://api.github.com/users/iaguis/orgs","repos_url":"https://api.github.com/users/iaguis/repos","events_url":"https://api.github.com/users/iaguis/events{/privacy}","received_events_url":"https://api.github.com/users/iaguis/received_events","type":"User","site_admin":false},"body":"We were writing the file directly to its final destination instead of\r\nwriting it to a temporary file and then renaming it. This caused file\r\ncorruption when running docker2aci several times in parallel.\r\n\r\nWe now write the squashed ACI to a temporary file with a random name and\r\nrename it atomically after the write is finished and the ACI validated.\r\n\r\nFixes #73 ","created_at":"2015-08-05T08:45:47Z","updated_at":"2015-08-07T13:37:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"280964f10bab1ee3db27178e76869f39ee4121cb","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/appc/docker2aci/pulls/76/commits","review_comments_url":"https://api.github.com/repos/appc/docker2aci/pulls/76/comments","review_comment_url":"https://api.github.com/repos/appc/docker2aci/pulls/comments{/number}","comments_url":"https://api.github.com/repos/appc/docker2aci/issues/76/comments","statuses_url":"https://api.github.com/repos/appc/docker2aci/statuses/86920c3b9012a1721d55310d148dff002dd8b9e2","head":{"label":"endocode:iaguis/parallel-docker2aci","ref":"iaguis/parallel-docker2aci","sha":"86920c3b9012a1721d55310d148dff002dd8b9e2","user":{"login":"endocode","id":4068543,"avatar_url":"https://avatars.githubusercontent.com/u/4068543?v=3","gravatar_id":"","url":"https://api.github.com/users/endocode","html_url":"https://github.com/endocode","followers_url":"https://api.github.com/users/endocode/followers","following_url":"https://api.github.com/users/endocode/following{/other_user}","gists_url":"https://api.github.com/users/endocode/gists{/gist_id}","starred_url":"https://api.github.com/users/endocode/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/endocode/subscriptions","organizations_url":"https://api.github.com/users/endocode/orgs","repos_url":"https://api.github.com/users/endocode/repos","events_url":"https://api.github.com/users/endocode/events{/privacy}","received_events_url":"https://api.github.com/users/endocode/received_events","type":"Organization","site_admin":false},"repo":{"id":29725967,"name":"docker2aci","full_name":"endocode/docker2aci","owner":{"login":"endocode","id":4068543,"avatar_url":"https://avatars.githubusercontent.com/u/4068543?v=3","gravatar_id":"","url":"https://api.github.com/users/endocode","html_url":"https://github.com/endocode","followers_url":"https://api.github.com/users/endocode/followers","following_url":"https://api.github.com/users/endocode/following{/other_user}","gists_url":"https://api.github.com/users/endocode/gists{/gist_id}","starred_url":"https://api.github.com/users/endocode/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/endocode/subscriptions","organizations_url":"https://api.github.com/users/endocode/orgs","repos_url":"https://api.github.com/users/endocode/repos","events_url":"https://api.github.com/users/endocode/events{/privacy}","received_events_url":"https://api.github.com/users/endocode/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/endocode/docker2aci","description":"Small tool to convert docker images to ACI","fork":true,"url":"https://api.github.com/repos/endocode/docker2aci","forks_url":"https://api.github.com/repos/endocode/docker2aci/forks","keys_url":"https://api.github.com/repos/endocode/docker2aci/keys{/key_id}","collaborators_url":"https://api.github.com/repos/endocode/docker2aci/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/endocode/docker2aci/teams","hooks_url":"https://api.github.com/repos/endocode/docker2aci/hooks","issue_events_url":"https://api.github.com/repos/endocode/docker2aci/issues/events{/number}","events_url":"https://api.github.com/repos/endocode/docker2aci/events","assignees_url":"https://api.github.com/repos/endocode/docker2aci/assignees{/user}","branches_url":"https://api.github.com/repos/endocode/docker2aci/branches{/branch}","tags_url":"https://api.github.com/repos/endocode/docker2aci/tags","blobs_url":"https://api.github.com/repos/endocode/docker2aci/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/endocode/docker2aci/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/endocode/docker2aci/git/refs{/sha}","trees_url":"https://api.github.com/repos/endocode/docker2aci/git/trees{/sha}","statuses_url":"https://api.github.com/repos/endocode/docker2aci/statuses/{sha}","languages_url":"https://api.github.com/repos/endocode/docker2aci/languages","stargazers_url":"https://api.github.com/repos/endocode/docker2aci/stargazers","contributors_url":"https://api.github.com/repos/endocode/docker2aci/contributors","subscribers_url":"https://api.github.com/repos/endocode/docker2aci/subscribers","subscription_url":"https://api.github.com/repos/endocode/docker2aci/subscription","commits_url":"https://api.github.com/repos/endocode/docker2aci/commits{/sha}","git_commits_url":"https://api.github.com/repos/endocode/docker2aci/git/commits{/sha}","comments_url":"https://api.github.com/repos/endocode/docker2aci/comments{/number}","issue_comment_url":"https://api.github.com/repos/endocode/docker2aci/issues/comments{/number}","contents_url":"https://api.github.com/repos/endocode/docker2aci/contents/{+path}","compare_url":"https://api.github.com/repos/endocode/docker2aci/compare/{base}...{head}","merges_url":"https://api.github.com/repos/endocode/docker2aci/merges","archive_url":"https://api.github.com/repos/endocode/docker2aci/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/endocode/docker2aci/downloads","issues_url":"https://api.github.com/repos/endocode/docker2aci/issues{/number}","pulls_url":"https://api.github.com/repos/endocode/docker2aci/pulls{/number}","milestones_url":"https://api.github.com/repos/endocode/docker2aci/milestones{/number}","notifications_url":"https://api.github.com/repos/endocode/docker2aci/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/endocode/docker2aci/labels{/name}","releases_url":"https://api.github.com/repos/endocode/docker2aci/releases{/id}","created_at":"2015-01-23T09:30:47Z","updated_at":"2015-05-23T16:09:49Z","pushed_at":"2015-08-07T13:13:41Z","git_url":"git://github.com/endocode/docker2aci.git","ssh_url":"git@github.com:endocode/docker2aci.git","clone_url":"https://github.com/endocode/docker2aci.git","svn_url":"https://github.com/endocode/docker2aci","homepage":null,"size":770,"stargazers_count":2,"watchers_count":2,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":2,"default_branch":"master"}},"base":{"label":"appc:master","ref":"master","sha":"f4921ff41174ce78fb57899b7ce1a713b5339a5b","user":{"login":"appc","id":10080092,"avatar_url":"https://avatars.githubusercontent.com/u/10080092?v=3","gravatar_id":"","url":"https://api.github.com/users/appc","html_url":"https://github.com/appc","followers_url":"https://api.github.com/users/appc/followers","following_url":"https://api.github.com/users/appc/following{/other_user}","gists_url":"https://api.github.com/users/appc/gists{/gist_id}","starred_url":"https://api.github.com/users/appc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/appc/subscriptions","organizations_url":"https://api.github.com/users/appc/orgs","repos_url":"https://api.github.com/users/appc/repos","events_url":"https://api.github.com/users/appc/events{/privacy}","received_events_url":"https://api.github.com/users/appc/received_events","type":"Organization","site_admin":false},"repo":{"id":29600667,"name":"docker2aci","full_name":"appc/docker2aci","owner":{"login":"appc","id":10080092,"avatar_url":"https://avatars.githubusercontent.com/u/10080092?v=3","gravatar_id":"","url":"https://api.github.com/users/appc","html_url":"https://github.com/appc","followers_url":"https://api.github.com/users/appc/followers","following_url":"https://api.github.com/users/appc/following{/other_user}","gists_url":"https://api.github.com/users/appc/gists{/gist_id}","starred_url":"https://api.github.com/users/appc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/appc/subscriptions","organizations_url":"https://api.github.com/users/appc/orgs","repos_url":"https://api.github.com/users/appc/repos","events_url":"https://api.github.com/users/appc/events{/privacy}","received_events_url":"https://api.github.com/users/appc/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/appc/docker2aci","description":"Small library and CLI tool to convert Docker images to ACI","fork":false,"url":"https://api.github.com/repos/appc/docker2aci","forks_url":"https://api.github.com/repos/appc/docker2aci/forks","keys_url":"https://api.github.com/repos/appc/docker2aci/keys{/key_id}","collaborators_url":"https://api.github.com/repos/appc/docker2aci/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/appc/docker2aci/teams","hooks_url":"https://api.github.com/repos/appc/docker2aci/hooks","issue_events_url":"https://api.github.com/repos/appc/docker2aci/issues/events{/number}","events_url":"https://api.github.com/repos/appc/docker2aci/events","assignees_url":"https://api.github.com/repos/appc/docker2aci/assignees{/user}","branches_url":"https://api.github.com/repos/appc/docker2aci/branches{/branch}","tags_url":"https://api.github.com/repos/appc/docker2aci/tags","blobs_url":"https://api.github.com/repos/appc/docker2aci/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/appc/docker2aci/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/appc/docker2aci/git/refs{/sha}","trees_url":"https://api.github.com/repos/appc/docker2aci/git/trees{/sha}","statuses_url":"https://api.github.com/repos/appc/docker2aci/statuses/{sha}","languages_url":"https://api.github.com/repos/appc/docker2aci/languages","stargazers_url":"https://api.github.com/repos/appc/docker2aci/stargazers","contributors_url":"https://api.github.com/repos/appc/docker2aci/contributors","subscribers_url":"https://api.github.com/repos/appc/docker2aci/subscribers","subscription_url":"https://api.github.com/repos/appc/docker2aci/subscription","commits_url":"https://api.github.com/repos/appc/docker2aci/commits{/sha}","git_commits_url":"https://api.github.com/repos/appc/docker2aci/git/commits{/sha}","comments_url":"https://api.github.com/repos/appc/docker2aci/comments{/number}","issue_comment_url":"https://api.github.com/repos/appc/docker2aci/issues/comments{/number}","contents_url":"https://api.github.com/repos/appc/docker2aci/contents/{+path}","compare_url":"https://api.github.com/repos/appc/docker2aci/compare/{base}...{head}","merges_url":"https://api.github.com/repos/appc/docker2aci/merges","archive_url":"https://api.github.com/repos/appc/docker2aci/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/appc/docker2aci/downloads","issues_url":"https://api.github.com/repos/appc/docker2aci/issues{/number}","pulls_url":"https://api.github.com/repos/appc/docker2aci/pulls{/number}","milestones_url":"https://api.github.com/repos/appc/docker2aci/milestones{/number}","notifications_url":"https://api.github.com/repos/appc/docker2aci/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/appc/docker2aci/labels{/name}","releases_url":"https://api.github.com/repos/appc/docker2aci/releases{/id}","created_at":"2015-01-21T17:03:40Z","updated_at":"2015-07-24T06:01:38Z","pushed_at":"2015-08-07T13:13:41Z","git_url":"git://github.com/appc/docker2aci.git","ssh_url":"git@github.com:appc/docker2aci.git","clone_url":"https://github.com/appc/docker2aci.git","svn_url":"https://github.com/appc/docker2aci","homepage":"","size":2926,"stargazers_count":84,"watchers_count":84,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":19,"mirror_url":null,"open_issues_count":11,"forks":19,"open_issues":11,"watchers":84,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/appc/docker2aci/pulls/76"},"html":{"href":"https://github.com/appc/docker2aci/pull/76"},"issue":{"href":"https://api.github.com/repos/appc/docker2aci/issues/76"},"comments":{"href":"https://api.github.com/repos/appc/docker2aci/issues/76/comments"},"review_comments":{"href":"https://api.github.com/repos/appc/docker2aci/pulls/76/comments"},"review_comment":{"href":"https://api.github.com/repos/appc/docker2aci/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/appc/docker2aci/pulls/76/commits"},"statuses":{"href":"https://api.github.com/repos/appc/docker2aci/statuses/86920c3b9012a1721d55310d148dff002dd8b9e2"}}}}