{"action":"created","comment":{"url":"https://api.github.com/repos/snapcore/snapcraft/pulls/comments/72900844","id":72900844,"diff_hunk":"@@ -435,3 +476,52 @@ def _get_source_type_from_uri(source, ignore_errors=False):\n         raise ValueError('local source is not a directory')\n \n     return source_type\n+\n+\n+def verify_checksum(source_checksum, checkfile):\n+    if source_checksum.startswith('http'):\n+        response = urllib.request.urlopen(source_checksum)\n+        data = response.read()\n+        source_checksum = data.decode('utf-8')\n+        if (\" \" in source_checksum):\n+            source_checksum = source_checksum.split(\" \", 1)[0]\n+        else:\n+            print('No file name detected in the checksum file, perhaps an '","path":"snapcraft/internal/sources.py","position":217,"original_position":217,"commit_id":"5bf0c4257322c7baec0a7b4cc2e724574063e18d","original_commit_id":"dd0f020d3db9fc533cabde6200e4fa5c332f29c0","user":{"login":"tsimonq2","id":3689821,"avatar_url":"https://avatars.githubusercontent.com/u/3689821?v=3","gravatar_id":"","url":"https://api.github.com/users/tsimonq2","html_url":"https://github.com/tsimonq2","followers_url":"https://api.github.com/users/tsimonq2/followers","following_url":"https://api.github.com/users/tsimonq2/following{/other_user}","gists_url":"https://api.github.com/users/tsimonq2/gists{/gist_id}","starred_url":"https://api.github.com/users/tsimonq2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tsimonq2/subscriptions","organizations_url":"https://api.github.com/users/tsimonq2/orgs","repos_url":"https://api.github.com/users/tsimonq2/repos","events_url":"https://api.github.com/users/tsimonq2/events{/privacy}","received_events_url":"https://api.github.com/users/tsimonq2/received_events","type":"User","site_admin":false},"body":"@sergiusens do you think it's **always** the case that the checksum file has a filename? If so, I'll correct it.","created_at":"2016-07-31T09:00:05Z","updated_at":"2016-07-31T09:00:05Z","html_url":"https://github.com/snapcore/snapcraft/pull/619#discussion_r72900844","pull_request_url":"https://api.github.com/repos/snapcore/snapcraft/pulls/619","_links":{"self":{"href":"https://api.github.com/repos/snapcore/snapcraft/pulls/comments/72900844"},"html":{"href":"https://github.com/snapcore/snapcraft/pull/619#discussion_r72900844"},"pull_request":{"href":"https://api.github.com/repos/snapcore/snapcraft/pulls/619"}}},"pull_request":{"url":"https://api.github.com/repos/snapcore/snapcraft/pulls/619","id":75797180,"html_url":"https://github.com/snapcore/snapcraft/pull/619","diff_url":"https://github.com/snapcore/snapcraft/pull/619.diff","patch_url":"https://github.com/snapcore/snapcraft/pull/619.patch","issue_url":"https://api.github.com/repos/snapcore/snapcraft/issues/619","number":619,"state":"open","locked":false,"title":"Add source-checksum option","user":{"login":"tsimonq2","id":3689821,"avatar_url":"https://avatars.githubusercontent.com/u/3689821?v=3","gravatar_id":"","url":"https://api.github.com/users/tsimonq2","html_url":"https://github.com/tsimonq2","followers_url":"https://api.github.com/users/tsimonq2/followers","following_url":"https://api.github.com/users/tsimonq2/following{/other_user}","gists_url":"https://api.github.com/users/tsimonq2/gists{/gist_id}","starred_url":"https://api.github.com/users/tsimonq2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tsimonq2/subscriptions","organizations_url":"https://api.github.com/users/tsimonq2/orgs","repos_url":"https://api.github.com/users/tsimonq2/repos","events_url":"https://api.github.com/users/tsimonq2/events{/privacy}","received_events_url":"https://api.github.com/users/tsimonq2/received_events","type":"User","site_admin":false},"body":"This adds an optional `source-checksum` tag to ensure download integrity by checking the checksum.\r\n\r\n## Features\r\n - It supports the following `source-type`s:\r\n  - `source-type: tar`\r\n  - `source-type: zip`\r\n - It supports the following checksums:\r\n  - `md5`\r\n  - `sha1`\r\n  - `sha224`\r\n  - `sha256`\r\n  - `sha384`\r\n  - `sha512`\r\n - You can use it in the following ways:\r\n  - `source-checksum: HASH` - raw hash\r\n  - `source-checksum: checksum.txt` - local file\r\n  - `source-checksum: http(s)://example.com/checksum` - remote URL\r\n\r\n## Failsafes\r\nIt has the following failsafes to ensure the code always works as intended:\r\n - Special exception for a checksum that doesn't match\r\n - Raises an exception for a checksum that is invalid, or incompatible with the checksums supported\r\n\r\n## Testing coverage\r\nI have the following testing in place:\r\n - Unit tests:\r\n  - Testing of each checksum in raw form with a created file (tar/zip) that has a static checksum\r\n  - Creation of a checksum file and checking the checksum with that local file\r\n  - Pulling http://tsimonq2.net/misc/snapcraft-checksum-tar and http://tsimonq2.net/misc/snapcraft-checksum-zip respectively and checking the checksum of the static file with those\r\n  - Checking for an invalid checksum\r\n - Integration tests:\r\n  - Testing of each checksum in raw form with a created file (tar/zip) that has a static checksum in the `snapcraft.yaml` files for `simple-tar` and `simple-zip`\r\n\r\n## Discrepancies between this specification and the source\r\nIf you find any difference between the code in this PR and the specification above, please comment, as that wasn't intended.","created_at":"2016-06-30T10:41:33Z","updated_at":"2016-07-31T09:00:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"afee76cc70c373177bfbbfad15e4591f799bdfb2","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/snapcore/snapcraft/pulls/619/commits","review_comments_url":"https://api.github.com/repos/snapcore/snapcraft/pulls/619/comments","review_comment_url":"https://api.github.com/repos/snapcore/snapcraft/pulls/comments{/number}","comments_url":"https://api.github.com/repos/snapcore/snapcraft/issues/619/comments","statuses_url":"https://api.github.com/repos/snapcore/snapcraft/statuses/5bf0c4257322c7baec0a7b4cc2e724574063e18d","head":{"label":"tsimonq2:downloaded-files-checksum-bug-1585913","ref":"downloaded-files-checksum-bug-1585913","sha":"5bf0c4257322c7baec0a7b4cc2e724574063e18d","user":{"login":"tsimonq2","id":3689821,"avatar_url":"https://avatars.githubusercontent.com/u/3689821?v=3","gravatar_id":"","url":"https://api.github.com/users/tsimonq2","html_url":"https://github.com/tsimonq2","followers_url":"https://api.github.com/users/tsimonq2/followers","following_url":"https://api.github.com/users/tsimonq2/following{/other_user}","gists_url":"https://api.github.com/users/tsimonq2/gists{/gist_id}","starred_url":"https://api.github.com/users/tsimonq2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tsimonq2/subscriptions","organizations_url":"https://api.github.com/users/tsimonq2/orgs","repos_url":"https://api.github.com/users/tsimonq2/repos","events_url":"https://api.github.com/users/tsimonq2/events{/privacy}","received_events_url":"https://api.github.com/users/tsimonq2/received_events","type":"User","site_admin":false},"repo":{"id":60866796,"name":"snapcraft","full_name":"tsimonq2/snapcraft","owner":{"login":"tsimonq2","id":3689821,"avatar_url":"https://avatars.githubusercontent.com/u/3689821?v=3","gravatar_id":"","url":"https://api.github.com/users/tsimonq2","html_url":"https://github.com/tsimonq2","followers_url":"https://api.github.com/users/tsimonq2/followers","following_url":"https://api.github.com/users/tsimonq2/following{/other_user}","gists_url":"https://api.github.com/users/tsimonq2/gists{/gist_id}","starred_url":"https://api.github.com/users/tsimonq2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tsimonq2/subscriptions","organizations_url":"https://api.github.com/users/tsimonq2/orgs","repos_url":"https://api.github.com/users/tsimonq2/repos","events_url":"https://api.github.com/users/tsimonq2/events{/privacy}","received_events_url":"https://api.github.com/users/tsimonq2/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tsimonq2/snapcraft","description":"Snapcraft is a delightful packaging tool","fork":true,"url":"https://api.github.com/repos/tsimonq2/snapcraft","forks_url":"https://api.github.com/repos/tsimonq2/snapcraft/forks","keys_url":"https://api.github.com/repos/tsimonq2/snapcraft/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tsimonq2/snapcraft/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tsimonq2/snapcraft/teams","hooks_url":"https://api.github.com/repos/tsimonq2/snapcraft/hooks","issue_events_url":"https://api.github.com/repos/tsimonq2/snapcraft/issues/events{/number}","events_url":"https://api.github.com/repos/tsimonq2/snapcraft/events","assignees_url":"https://api.github.com/repos/tsimonq2/snapcraft/assignees{/user}","branches_url":"https://api.github.com/repos/tsimonq2/snapcraft/branches{/branch}","tags_url":"https://api.github.com/repos/tsimonq2/snapcraft/tags","blobs_url":"https://api.github.com/repos/tsimonq2/snapcraft/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tsimonq2/snapcraft/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tsimonq2/snapcraft/git/refs{/sha}","trees_url":"https://api.github.com/repos/tsimonq2/snapcraft/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tsimonq2/snapcraft/statuses/{sha}","languages_url":"https://api.github.com/repos/tsimonq2/snapcraft/languages","stargazers_url":"https://api.github.com/repos/tsimonq2/snapcraft/stargazers","contributors_url":"https://api.github.com/repos/tsimonq2/snapcraft/contributors","subscribers_url":"https://api.github.com/repos/tsimonq2/snapcraft/subscribers","subscription_url":"https://api.github.com/repos/tsimonq2/snapcraft/subscription","commits_url":"https://api.github.com/repos/tsimonq2/snapcraft/commits{/sha}","git_commits_url":"https://api.github.com/repos/tsimonq2/snapcraft/git/commits{/sha}","comments_url":"https://api.github.com/repos/tsimonq2/snapcraft/comments{/number}","issue_comment_url":"https://api.github.com/repos/tsimonq2/snapcraft/issues/comments{/number}","contents_url":"https://api.github.com/repos/tsimonq2/snapcraft/contents/{+path}","compare_url":"https://api.github.com/repos/tsimonq2/snapcraft/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tsimonq2/snapcraft/merges","archive_url":"https://api.github.com/repos/tsimonq2/snapcraft/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tsimonq2/snapcraft/downloads","issues_url":"https://api.github.com/repos/tsimonq2/snapcraft/issues{/number}","pulls_url":"https://api.github.com/repos/tsimonq2/snapcraft/pulls{/number}","milestones_url":"https://api.github.com/repos/tsimonq2/snapcraft/milestones{/number}","notifications_url":"https://api.github.com/repos/tsimonq2/snapcraft/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tsimonq2/snapcraft/labels{/name}","releases_url":"https://api.github.com/repos/tsimonq2/snapcraft/releases{/id}","deployments_url":"https://api.github.com/repos/tsimonq2/snapcraft/deployments","created_at":"2016-06-10T17:53:26Z","updated_at":"2016-06-10T17:53:27Z","pushed_at":"2016-07-31T08:58:38Z","git_url":"git://github.com/tsimonq2/snapcraft.git","ssh_url":"git@github.com:tsimonq2/snapcraft.git","clone_url":"https://github.com/tsimonq2/snapcraft.git","svn_url":"https://github.com/tsimonq2/snapcraft","homepage":null,"size":4486,"stargazers_count":0,"watchers_count":0,"language":"Python","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":0,"default_branch":"master"}},"base":{"label":"snapcore:master","ref":"master","sha":"fe96e8dbda93e5dab6c70d2d2a61d70a93f4b400","user":{"login":"snapcore","id":19532717,"avatar_url":"https://avatars.githubusercontent.com/u/19532717?v=3","gravatar_id":"","url":"https://api.github.com/users/snapcore","html_url":"https://github.com/snapcore","followers_url":"https://api.github.com/users/snapcore/followers","following_url":"https://api.github.com/users/snapcore/following{/other_user}","gists_url":"https://api.github.com/users/snapcore/gists{/gist_id}","starred_url":"https://api.github.com/users/snapcore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/snapcore/subscriptions","organizations_url":"https://api.github.com/users/snapcore/orgs","repos_url":"https://api.github.com/users/snapcore/repos","events_url":"https://api.github.com/users/snapcore/events{/privacy}","received_events_url":"https://api.github.com/users/snapcore/received_events","type":"Organization","site_admin":false},"repo":{"id":45199136,"name":"snapcraft","full_name":"snapcore/snapcraft","owner":{"login":"snapcore","id":19532717,"avatar_url":"https://avatars.githubusercontent.com/u/19532717?v=3","gravatar_id":"","url":"https://api.github.com/users/snapcore","html_url":"https://github.com/snapcore","followers_url":"https://api.github.com/users/snapcore/followers","following_url":"https://api.github.com/users/snapcore/following{/other_user}","gists_url":"https://api.github.com/users/snapcore/gists{/gist_id}","starred_url":"https://api.github.com/users/snapcore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/snapcore/subscriptions","organizations_url":"https://api.github.com/users/snapcore/orgs","repos_url":"https://api.github.com/users/snapcore/repos","events_url":"https://api.github.com/users/snapcore/events{/privacy}","received_events_url":"https://api.github.com/users/snapcore/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/snapcore/snapcraft","description":"Snapcraft is a delightful packaging tool","fork":false,"url":"https://api.github.com/repos/snapcore/snapcraft","forks_url":"https://api.github.com/repos/snapcore/snapcraft/forks","keys_url":"https://api.github.com/repos/snapcore/snapcraft/keys{/key_id}","collaborators_url":"https://api.github.com/repos/snapcore/snapcraft/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/snapcore/snapcraft/teams","hooks_url":"https://api.github.com/repos/snapcore/snapcraft/hooks","issue_events_url":"https://api.github.com/repos/snapcore/snapcraft/issues/events{/number}","events_url":"https://api.github.com/repos/snapcore/snapcraft/events","assignees_url":"https://api.github.com/repos/snapcore/snapcraft/assignees{/user}","branches_url":"https://api.github.com/repos/snapcore/snapcraft/branches{/branch}","tags_url":"https://api.github.com/repos/snapcore/snapcraft/tags","blobs_url":"https://api.github.com/repos/snapcore/snapcraft/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/snapcore/snapcraft/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/snapcore/snapcraft/git/refs{/sha}","trees_url":"https://api.github.com/repos/snapcore/snapcraft/git/trees{/sha}","statuses_url":"https://api.github.com/repos/snapcore/snapcraft/statuses/{sha}","languages_url":"https://api.github.com/repos/snapcore/snapcraft/languages","stargazers_url":"https://api.github.com/repos/snapcore/snapcraft/stargazers","contributors_url":"https://api.github.com/repos/snapcore/snapcraft/contributors","subscribers_url":"https://api.github.com/repos/snapcore/snapcraft/subscribers","subscription_url":"https://api.github.com/repos/snapcore/snapcraft/subscription","commits_url":"https://api.github.com/repos/snapcore/snapcraft/commits{/sha}","git_commits_url":"https://api.github.com/repos/snapcore/snapcraft/git/commits{/sha}","comments_url":"https://api.github.com/repos/snapcore/snapcraft/comments{/number}","issue_comment_url":"https://api.github.com/repos/snapcore/snapcraft/issues/comments{/number}","contents_url":"https://api.github.com/repos/snapcore/snapcraft/contents/{+path}","compare_url":"https://api.github.com/repos/snapcore/snapcraft/compare/{base}...{head}","merges_url":"https://api.github.com/repos/snapcore/snapcraft/merges","archive_url":"https://api.github.com/repos/snapcore/snapcraft/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/snapcore/snapcraft/downloads","issues_url":"https://api.github.com/repos/snapcore/snapcraft/issues{/number}","pulls_url":"https://api.github.com/repos/snapcore/snapcraft/pulls{/number}","milestones_url":"https://api.github.com/repos/snapcore/snapcraft/milestones{/number}","notifications_url":"https://api.github.com/repos/snapcore/snapcraft/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/snapcore/snapcraft/labels{/name}","releases_url":"https://api.github.com/repos/snapcore/snapcraft/releases{/id}","deployments_url":"https://api.github.com/repos/snapcore/snapcraft/deployments","created_at":"2015-10-29T17:23:15Z","updated_at":"2016-07-29T07:08:35Z","pushed_at":"2016-07-31T08:58:38Z","git_url":"git://github.com/snapcore/snapcraft.git","ssh_url":"git@github.com:snapcore/snapcraft.git","clone_url":"https://github.com/snapcore/snapcraft.git","svn_url":"https://github.com/snapcore/snapcraft","homepage":null,"size":6444,"stargazers_count":193,"watchers_count":193,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":95,"mirror_url":null,"open_issues_count":33,"forks":95,"open_issues":33,"watchers":193,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/snapcore/snapcraft/pulls/619"},"html":{"href":"https://github.com/snapcore/snapcraft/pull/619"},"issue":{"href":"https://api.github.com/repos/snapcore/snapcraft/issues/619"},"comments":{"href":"https://api.github.com/repos/snapcore/snapcraft/issues/619/comments"},"review_comments":{"href":"https://api.github.com/repos/snapcore/snapcraft/pulls/619/comments"},"review_comment":{"href":"https://api.github.com/repos/snapcore/snapcraft/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/snapcore/snapcraft/pulls/619/commits"},"statuses":{"href":"https://api.github.com/repos/snapcore/snapcraft/statuses/5bf0c4257322c7baec0a7b4cc2e724574063e18d"}}}}
{"actor":{"display_login":"tsimonq2"}}