{"action":"created","comment":{"url":"https://api.github.com/repos/snapcore/snapd/pulls/comments/178830419","pull_request_review_id":108954994,"id":178830419,"diff_hunk":"@@ -0,0 +1,245 @@\n+// -*- Mode: Go; indent-tabs-mode: t -*-\n+\n+/*\n+ * Copyright (C) 2018 Canonical Ltd\n+ *\n+ * This program is free software: you can redistribute it and/or modify\n+ * it under the terms of the GNU General Public License version 3 as\n+ * published by the Free Software Foundation.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.\n+ *\n+ */\n+\n+package backend\n+\n+import (\n+\t\"archive/zip\"\n+\t\"crypto\"\n+\t\"encoding/json\"\n+\t\"fmt\"\n+\t\"hash\"\n+\t\"io\"\n+\t\"os\"\n+\t\"os/exec\"\n+\t\"path/filepath\"\n+\t\"sort\"\n+\t\"time\"\n+\n+\t\"golang.org/x/net/context\"\n+\n+\t\"github.com/snapcore/snapd/client\"\n+\t\"github.com/snapcore/snapd/dirs\"\n+\t\"github.com/snapcore/snapd/logger\"\n+\t\"github.com/snapcore/snapd/osutil\"\n+\t\"github.com/snapcore/snapd/snap\"\n+\t\"github.com/snapcore/snapd/strutil\"\n+)\n+\n+const (\n+\tarchiveName  = \"archive.tgz\"\n+\tmetadataName = \"meta.json\"\n+\tmetaHashName = \"meta.sha3_384\"\n+\n+\tuserArchivePrefix = \"user/\"\n+\tuserArchiveSuffix = \".tgz\"\n+)\n+\n+var (\n+\tdirOpen  = os.Open\n+\tdirNames = (*os.File).Readdirnames\n+\topen     = Open\n+)\n+\n+// Iter loops over all snapshots in the snapshots directory, applying the\n+// given function to each. The snapshot will be closed after the function\n+// returns. If the function returns error, iteration is stopped (and if the\n+// error isn't EOF, it's returned as the error of the iterator).\n+func Iter(ctx context.Context, f func(*Reader) error) error {\n+\tif err := ctx.Err(); err != nil {\n+\t\treturn err\n+\t}\n+\n+\tdir, err := dirOpen(dirs.SnapshotDir)\n+\tif err != nil {\n+\t\tif osutil.IsDirNotExist(err) {\n+\t\t\t// no dir -> no snapshots\n+\t\t\treturn nil\n+\t\t}\n+\t\treturn fmt.Errorf(\"cannot open snapshots directory: %v\", err)\n+\t}\n+\tdefer dir.Close()\n+\n+\tvar names []string\n+\tfor err == nil {\n+\t\tnames, err = dirNames(dir, 100)\n+\t\tfor _, name := range names {\n+\t\t\tif err = ctx.Err(); err != nil {\n+\t\t\t\tbreak\n+\t\t\t}\n+\n+\t\t\tfilename := filepath.Join(dirs.SnapshotDir, name)\n+\t\t\trsh, openError := open(filename)\n+\t\t\tif rsh != nil {\n+\t\t\t\terr = f(rsh)\n+\t\t\t} else {\n+\t\t\t\t// TODO: use warnings instead\n+\t\t\t\tlogger.Noticef(\"cannot open snapshot %q: %v\", name, openError)\n+\t\t\t}\n+\t\t\tif openError == nil {","path":"overlord/snapshotstate/backend/backend.go","position":95,"original_position":95,"commit_id":"78fd782b94f5a29a25e5d5351948a5d36d37a29a","original_commit_id":"78fd782b94f5a29a25e5d5351948a5d36d37a29a","user":{"login":"chipaca","id":1543430,"avatar_url":"https://avatars1.githubusercontent.com/u/1543430?v=4","gravatar_id":"","url":"https://api.github.com/users/chipaca","html_url":"https://github.com/chipaca","followers_url":"https://api.github.com/users/chipaca/followers","following_url":"https://api.github.com/users/chipaca/following{/other_user}","gists_url":"https://api.github.com/users/chipaca/gists{/gist_id}","starred_url":"https://api.github.com/users/chipaca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chipaca/subscriptions","organizations_url":"https://api.github.com/users/chipaca/orgs","repos_url":"https://api.github.com/users/chipaca/repos","events_url":"https://api.github.com/users/chipaca/events{/privacy}","received_events_url":"https://api.github.com/users/chipaca/received_events","type":"User","site_admin":false},"body":"it's documented on open, but I'll add a comment explaining this at this side as well.","created_at":"2018-04-03T13:50:10Z","updated_at":"2018-04-03T13:50:11Z","html_url":"https://github.com/snapcore/snapd/pull/4588#discussion_r178830419","pull_request_url":"https://api.github.com/repos/snapcore/snapd/pulls/4588","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/comments/178830419"},"html":{"href":"https://github.com/snapcore/snapd/pull/4588#discussion_r178830419"},"pull_request":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/4588"}},"in_reply_to_id":178466950},"pull_request":{"url":"https://api.github.com/repos/snapcore/snapd/pulls/4588","id":166605533,"html_url":"https://github.com/snapcore/snapd/pull/4588","diff_url":"https://github.com/snapcore/snapd/pull/4588.diff","patch_url":"https://github.com/snapcore/snapd/pull/4588.patch","issue_url":"https://api.github.com/repos/snapcore/snapd/issues/4588","number":4588,"state":"open","locked":false,"title":"Snapshots!","user":{"login":"chipaca","id":1543430,"avatar_url":"https://avatars1.githubusercontent.com/u/1543430?v=4","gravatar_id":"","url":"https://api.github.com/users/chipaca","html_url":"https://github.com/chipaca","followers_url":"https://api.github.com/users/chipaca/followers","following_url":"https://api.github.com/users/chipaca/following{/other_user}","gists_url":"https://api.github.com/users/chipaca/gists{/gist_id}","starred_url":"https://api.github.com/users/chipaca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chipaca/subscriptions","organizations_url":"https://api.github.com/users/chipaca/orgs","repos_url":"https://api.github.com/users/chipaca/repos","events_url":"https://api.github.com/users/chipaca/events{/privacy}","received_events_url":"https://api.github.com/users/chipaca/received_events","type":"User","site_admin":false},"body":"This is a bit of a cow of a PR, but it contains just 5 commits. Look at the commits independently and it should be a lot easier to review.\r\n\r\nAlso, this is missing all sorts of tests; I'm looking for feedback on the direction taken, and will add tests if it doesn't turn out that I have to refactor the whole thing still.\r\n\r\n----\r\nThings left for followup PRs:\r\n* restore to current revision, unless epoch says no (this code restores to original revno)\r\n* restore config (this code saves it but doesn't restore it)\r\n* shorter human timestamp\r\n* ...?","created_at":"2018-02-01T17:41:18Z","updated_at":"2018-04-03T13:50:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"10e6f09f941fe717b21e19669c43584033c1b731","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/snapcore/snapd/pulls/4588/commits","review_comments_url":"https://api.github.com/repos/snapcore/snapd/pulls/4588/comments","review_comment_url":"https://api.github.com/repos/snapcore/snapd/pulls/comments{/number}","comments_url":"https://api.github.com/repos/snapcore/snapd/issues/4588/comments","statuses_url":"https://api.github.com/repos/snapcore/snapd/statuses/78fd782b94f5a29a25e5d5351948a5d36d37a29a","head":{"label":"chipaca:snapshots","ref":"snapshots","sha":"78fd782b94f5a29a25e5d5351948a5d36d37a29a","user":{"login":"chipaca","id":1543430,"avatar_url":"https://avatars1.githubusercontent.com/u/1543430?v=4","gravatar_id":"","url":"https://api.github.com/users/chipaca","html_url":"https://github.com/chipaca","followers_url":"https://api.github.com/users/chipaca/followers","following_url":"https://api.github.com/users/chipaca/following{/other_user}","gists_url":"https://api.github.com/users/chipaca/gists{/gist_id}","starred_url":"https://api.github.com/users/chipaca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chipaca/subscriptions","organizations_url":"https://api.github.com/users/chipaca/orgs","repos_url":"https://api.github.com/users/chipaca/repos","events_url":"https://api.github.com/users/chipaca/events{/privacy}","received_events_url":"https://api.github.com/users/chipaca/received_events","type":"User","site_admin":false},"repo":{"id":45061368,"name":"snappy","full_name":"chipaca/snappy","owner":{"login":"chipaca","id":1543430,"avatar_url":"https://avatars1.githubusercontent.com/u/1543430?v=4","gravatar_id":"","url":"https://api.github.com/users/chipaca","html_url":"https://github.com/chipaca","followers_url":"https://api.github.com/users/chipaca/followers","following_url":"https://api.github.com/users/chipaca/following{/other_user}","gists_url":"https://api.github.com/users/chipaca/gists{/gist_id}","starred_url":"https://api.github.com/users/chipaca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chipaca/subscriptions","organizations_url":"https://api.github.com/users/chipaca/orgs","repos_url":"https://api.github.com/users/chipaca/repos","events_url":"https://api.github.com/users/chipaca/events{/privacy}","received_events_url":"https://api.github.com/users/chipaca/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/chipaca/snappy","description":"Snappy is the software at the heart of Ubuntu Core.","fork":true,"url":"https://api.github.com/repos/chipaca/snappy","forks_url":"https://api.github.com/repos/chipaca/snappy/forks","keys_url":"https://api.github.com/repos/chipaca/snappy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chipaca/snappy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chipaca/snappy/teams","hooks_url":"https://api.github.com/repos/chipaca/snappy/hooks","issue_events_url":"https://api.github.com/repos/chipaca/snappy/issues/events{/number}","events_url":"https://api.github.com/repos/chipaca/snappy/events","assignees_url":"https://api.github.com/repos/chipaca/snappy/assignees{/user}","branches_url":"https://api.github.com/repos/chipaca/snappy/branches{/branch}","tags_url":"https://api.github.com/repos/chipaca/snappy/tags","blobs_url":"https://api.github.com/repos/chipaca/snappy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chipaca/snappy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chipaca/snappy/git/refs{/sha}","trees_url":"https://api.github.com/repos/chipaca/snappy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chipaca/snappy/statuses/{sha}","languages_url":"https://api.github.com/repos/chipaca/snappy/languages","stargazers_url":"https://api.github.com/repos/chipaca/snappy/stargazers","contributors_url":"https://api.github.com/repos/chipaca/snappy/contributors","subscribers_url":"https://api.github.com/repos/chipaca/snappy/subscribers","subscription_url":"https://api.github.com/repos/chipaca/snappy/subscription","commits_url":"https://api.github.com/repos/chipaca/snappy/commits{/sha}","git_commits_url":"https://api.github.com/repos/chipaca/snappy/git/commits{/sha}","comments_url":"https://api.github.com/repos/chipaca/snappy/comments{/number}","issue_comment_url":"https://api.github.com/repos/chipaca/snappy/issues/comments{/number}","contents_url":"https://api.github.com/repos/chipaca/snappy/contents/{+path}","compare_url":"https://api.github.com/repos/chipaca/snappy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chipaca/snappy/merges","archive_url":"https://api.github.com/repos/chipaca/snappy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chipaca/snappy/downloads","issues_url":"https://api.github.com/repos/chipaca/snappy/issues{/number}","pulls_url":"https://api.github.com/repos/chipaca/snappy/pulls{/number}","milestones_url":"https://api.github.com/repos/chipaca/snappy/milestones{/number}","notifications_url":"https://api.github.com/repos/chipaca/snappy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chipaca/snappy/labels{/name}","releases_url":"https://api.github.com/repos/chipaca/snappy/releases{/id}","deployments_url":"https://api.github.com/repos/chipaca/snappy/deployments","created_at":"2015-10-27T18:26:51Z","updated_at":"2018-04-03T09:47:51Z","pushed_at":"2018-04-03T09:47:58Z","git_url":"git://github.com/chipaca/snappy.git","ssh_url":"git@github.com:chipaca/snappy.git","clone_url":"https://github.com/chipaca/snappy.git","svn_url":"https://github.com/chipaca/snappy","homepage":null,"size":61478,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"gpl-3.0","name":"GNU General Public License v3.0","spdx_id":"GPL-3.0","url":"https://api.github.com/licenses/gpl-3.0"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"snapcore:master","ref":"master","sha":"8917e08a19422e8cf0a9751e2bf1d6b777d79d20","user":{"login":"snapcore","id":19532717,"avatar_url":"https://avatars1.githubusercontent.com/u/19532717?v=4","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":44672744,"name":"snapd","full_name":"snapcore/snapd","owner":{"login":"snapcore","id":19532717,"avatar_url":"https://avatars1.githubusercontent.com/u/19532717?v=4","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/snapd","description":"The snapd and snap tools enable systems to work with .snap files.","fork":false,"url":"https://api.github.com/repos/snapcore/snapd","forks_url":"https://api.github.com/repos/snapcore/snapd/forks","keys_url":"https://api.github.com/repos/snapcore/snapd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/snapcore/snapd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/snapcore/snapd/teams","hooks_url":"https://api.github.com/repos/snapcore/snapd/hooks","issue_events_url":"https://api.github.com/repos/snapcore/snapd/issues/events{/number}","events_url":"https://api.github.com/repos/snapcore/snapd/events","assignees_url":"https://api.github.com/repos/snapcore/snapd/assignees{/user}","branches_url":"https://api.github.com/repos/snapcore/snapd/branches{/branch}","tags_url":"https://api.github.com/repos/snapcore/snapd/tags","blobs_url":"https://api.github.com/repos/snapcore/snapd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/snapcore/snapd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/snapcore/snapd/git/refs{/sha}","trees_url":"https://api.github.com/repos/snapcore/snapd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/snapcore/snapd/statuses/{sha}","languages_url":"https://api.github.com/repos/snapcore/snapd/languages","stargazers_url":"https://api.github.com/repos/snapcore/snapd/stargazers","contributors_url":"https://api.github.com/repos/snapcore/snapd/contributors","subscribers_url":"https://api.github.com/repos/snapcore/snapd/subscribers","subscription_url":"https://api.github.com/repos/snapcore/snapd/subscription","commits_url":"https://api.github.com/repos/snapcore/snapd/commits{/sha}","git_commits_url":"https://api.github.com/repos/snapcore/snapd/git/commits{/sha}","comments_url":"https://api.github.com/repos/snapcore/snapd/comments{/number}","issue_comment_url":"https://api.github.com/repos/snapcore/snapd/issues/comments{/number}","contents_url":"https://api.github.com/repos/snapcore/snapd/contents/{+path}","compare_url":"https://api.github.com/repos/snapcore/snapd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/snapcore/snapd/merges","archive_url":"https://api.github.com/repos/snapcore/snapd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/snapcore/snapd/downloads","issues_url":"https://api.github.com/repos/snapcore/snapd/issues{/number}","pulls_url":"https://api.github.com/repos/snapcore/snapd/pulls{/number}","milestones_url":"https://api.github.com/repos/snapcore/snapd/milestones{/number}","notifications_url":"https://api.github.com/repos/snapcore/snapd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/snapcore/snapd/labels{/name}","releases_url":"https://api.github.com/repos/snapcore/snapd/releases{/id}","deployments_url":"https://api.github.com/repos/snapcore/snapd/deployments","created_at":"2015-10-21T11:51:46Z","updated_at":"2018-04-03T09:48:05Z","pushed_at":"2018-04-03T12:57:02Z","git_url":"git://github.com/snapcore/snapd.git","ssh_url":"git@github.com:snapcore/snapd.git","clone_url":"https://github.com/snapcore/snapd.git","svn_url":"https://github.com/snapcore/snapd","homepage":"","size":61516,"stargazers_count":909,"watchers_count":909,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":228,"mirror_url":null,"archived":false,"open_issues_count":42,"license":{"key":"gpl-3.0","name":"GNU General Public License v3.0","spdx_id":"GPL-3.0","url":"https://api.github.com/licenses/gpl-3.0"},"forks":228,"open_issues":42,"watchers":909,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/4588"},"html":{"href":"https://github.com/snapcore/snapd/pull/4588"},"issue":{"href":"https://api.github.com/repos/snapcore/snapd/issues/4588"},"comments":{"href":"https://api.github.com/repos/snapcore/snapd/issues/4588/comments"},"review_comments":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/4588/comments"},"review_comment":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/4588/commits"},"statuses":{"href":"https://api.github.com/repos/snapcore/snapd/statuses/78fd782b94f5a29a25e5d5351948a5d36d37a29a"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"chipaca"}}