{"action":"created","comment":{"url":"https://api.github.com/repos/snapcore/snapd/pulls/comments/92558633","pull_request_review_id":13074685,"id":92558633,"diff_hunk":"@@ -512,3 +518,116 @@ func checkAliasConflict(st *state.State, snapName, alias string) error {\n \t\treturn nil\n \t})\n }\n+\n+// AutoAliases allows to hook support for retrieving auto-aliases of a snap.\n+var AutoAliases func(st *state.State, info *snap.Info) ([]string, error)\n+\n+// AutoAliasesDelta compares the alias statuses with the current snap\n+// declaration for the installed snaps with the given names (or all if\n+// names is empty) and returns new and retired auto-aliases by snap\n+// name. It accounts for already set enabled/disabled statuses but\n+// does not check for conflicts.\n+func AutoAliasesDelta(st *state.State, names []string) (new map[string][]string, retired map[string][]string, err error) {\n+\tvar snapStates map[string]*SnapState\n+\tif len(names) == 0 {\n+\t\tvar err error\n+\t\tsnapStates, err = All(st)\n+\t\tif err != nil {\n+\t\t\treturn nil, nil, err\n+\t\t}\n+\t} else {\n+\t\tsnapStates = make(map[string]*SnapState, len(names))\n+\t\tfor _, name := range names {\n+\t\t\tvar snapst SnapState\n+\t\t\terr := Get(st, name, &snapst)\n+\t\t\tif err != nil {\n+\t\t\t\treturn nil, nil, err\n+\t\t\t}\n+\t\t\tsnapStates[name] = &snapst\n+\t\t}\n+\t}\n+\tvar firstErr error\n+\tnew = make(map[string][]string)\n+\tretired = make(map[string][]string)\n+\tfor snapName, snapst := range snapStates {\n+\t\taliasStatuses, err := getAliases(st, snapName)\n+\t\tif err != nil && err != state.ErrNoState {\n+\t\t\tif firstErr == nil {\n+\t\t\t\tfirstErr = err\n+\t\t\t}\n+\t\t\tcontinue\n+\t\t}\n+\t\tinfo, err := snapst.CurrentInfo()\n+\t\tif err != nil {\n+\t\t\tif firstErr == nil {\n+\t\t\t\tfirstErr = err\n+\t\t\t}\n+\t\t\tcontinue\n+\t\t}\n+\t\tautoAliases, err := AutoAliases(st, info)\n+\t\tif err != nil {\n+\t\t\tif firstErr == nil {\n+\t\t\t\tfirstErr = err\n+\t\t\t}\n+\t\t\tcontinue\n+\t\t}\n+\t\tautoSet := make(map[string]bool, len(autoAliases))\n+\t\tfor _, alias := range autoAliases {\n+\t\t\tautoSet[alias] = true\n+\t\t\tif aliasStatuses[alias] == \"\" { // not auto, or disabled, or enabled\n+\t\t\t\tnew[snapName] = append(new[snapName], alias)\n+\t\t\t}\n+\t\t}\n+\t\tfor alias, curStatus := range aliasStatuses {\n+\t\t\tif curStatus == \"auto\" && !autoSet[alias] {\n+\t\t\t\tretired[snapName] = append(retired[snapName], alias)\n+\t\t\t}\n+\t\t}\n+\t}\n+\treturn new, retired, firstErr\n+}\n+\n+func (m *SnapManager) doSetAutoAliases(t *state.Task, _ *tomb.Tomb) error {\n+\tst := t.State()\n+\tst.Lock()\n+\tdefer st.Unlock()\n+\tsnapsup, snapst, err := snapSetupAndState(t)\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\tsnapName := snapsup.Name()\n+\tcurInfo, err := snapst.CurrentInfo()\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\taliasStatuses, err := getAliases(st, snapName)\n+\tif err != nil && err != state.ErrNoState {\n+\t\treturn err\n+\t}\n+\tt.Set(\"old-aliases\", aliasStatuses)\n+\tif aliasStatuses == nil {\n+\t\taliasStatuses = make(map[string]string)\n+\t}\n+\tallNew, allRetired, err := AutoAliasesDelta(st, []string{snapName})\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\tfor _, alias := range allRetired[snapName] {\n+\t\tdelete(aliasStatuses, alias)\n+\t}\n+\n+\tfor _, alias := range allNew[snapName] {\n+\t\taliasApp := curInfo.Aliases[alias]\n+\t\tif aliasApp == nil {\n+\t\t\t// not a known alias anymore or yet, skip\n+\t\t\tcontinue\n+\t\t}\n+\t\terr := checkAliasConflict(st, snapName, alias)\n+\t\tif err != nil {","path":"overlord/snapstate/aliases.go","position":195,"original_position":195,"commit_id":"71a2346aed03ad688e26e5bca188b6d7287af530","original_commit_id":"71a2346aed03ad688e26e5bca188b6d7287af530","user":{"login":"mvo5","id":914418,"avatar_url":"https://avatars.githubusercontent.com/u/914418?v=3","gravatar_id":"","url":"https://api.github.com/users/mvo5","html_url":"https://github.com/mvo5","followers_url":"https://api.github.com/users/mvo5/followers","following_url":"https://api.github.com/users/mvo5/following{/other_user}","gists_url":"https://api.github.com/users/mvo5/gists{/gist_id}","starred_url":"https://api.github.com/users/mvo5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mvo5/subscriptions","organizations_url":"https://api.github.com/users/mvo5/orgs","repos_url":"https://api.github.com/users/mvo5/repos","events_url":"https://api.github.com/users/mvo5/events{/privacy}","received_events_url":"https://api.github.com/users/mvo5/received_events","type":"User","site_admin":false},"body":"Maybe log a warning and continue?","created_at":"2016-12-15T07:52:11Z","updated_at":"2016-12-15T07:52:45Z","html_url":"https://github.com/snapcore/snapd/pull/2485#discussion_r92558633","pull_request_url":"https://api.github.com/repos/snapcore/snapd/pulls/2485","_links":{"self":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/comments/92558633"},"html":{"href":"https://github.com/snapcore/snapd/pull/2485#discussion_r92558633"},"pull_request":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/2485"}}},"pull_request":{"url":"https://api.github.com/repos/snapcore/snapd/pulls/2485","id":98017618,"html_url":"https://github.com/snapcore/snapd/pull/2485","diff_url":"https://github.com/snapcore/snapd/pull/2485.diff","patch_url":"https://github.com/snapcore/snapd/pull/2485.patch","issue_url":"https://api.github.com/repos/snapcore/snapd/issues/2485","number":2485,"state":"open","locked":false,"title":"overlord: apply auto-aliases information from the snap-declaration on install or refresh","user":{"login":"pedronis","id":975757,"avatar_url":"https://avatars.githubusercontent.com/u/975757?v=3","gravatar_id":"","url":"https://api.github.com/users/pedronis","html_url":"https://github.com/pedronis","followers_url":"https://api.github.com/users/pedronis/followers","following_url":"https://api.github.com/users/pedronis/following{/other_user}","gists_url":"https://api.github.com/users/pedronis/gists{/gist_id}","starred_url":"https://api.github.com/users/pedronis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pedronis/subscriptions","organizations_url":"https://api.github.com/users/pedronis/orgs","repos_url":"https://api.github.com/users/pedronis/repos","events_url":"https://api.github.com/users/pedronis/events{/privacy}","received_events_url":"https://api.github.com/users/pedronis/received_events","type":"User","site_admin":false},"body":"This first add support for the \"auto\" status of an alias through the pre-existing infrastructure,  then it adds support to apply auto-aliases information from the snap-declaration on install and refresh of a snap. It adds overlord integration tests in managers_test.go about this support.\r\n\r\nlater TODO:\r\n* e2e spread test\r\n* retire dropped auto-aliases earlier/together in refreshes to support transfers more gracefully\r\n* apply changes to auto-aliases even if the snap doesn't have a new revision?","created_at":"2016-12-14T19:20:32Z","updated_at":"2016-12-15T07:52:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2ecefd1362f9b661fd8e37c3c2dc98e4048c4a1b","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/snapcore/snapd/pulls/2485/commits","review_comments_url":"https://api.github.com/repos/snapcore/snapd/pulls/2485/comments","review_comment_url":"https://api.github.com/repos/snapcore/snapd/pulls/comments{/number}","comments_url":"https://api.github.com/repos/snapcore/snapd/issues/2485/comments","statuses_url":"https://api.github.com/repos/snapcore/snapd/statuses/71a2346aed03ad688e26e5bca188b6d7287af530","head":{"label":"pedronis:auto-aliases","ref":"auto-aliases","sha":"71a2346aed03ad688e26e5bca188b6d7287af530","user":{"login":"pedronis","id":975757,"avatar_url":"https://avatars.githubusercontent.com/u/975757?v=3","gravatar_id":"","url":"https://api.github.com/users/pedronis","html_url":"https://github.com/pedronis","followers_url":"https://api.github.com/users/pedronis/followers","following_url":"https://api.github.com/users/pedronis/following{/other_user}","gists_url":"https://api.github.com/users/pedronis/gists{/gist_id}","starred_url":"https://api.github.com/users/pedronis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pedronis/subscriptions","organizations_url":"https://api.github.com/users/pedronis/orgs","repos_url":"https://api.github.com/users/pedronis/repos","events_url":"https://api.github.com/users/pedronis/events{/privacy}","received_events_url":"https://api.github.com/users/pedronis/received_events","type":"User","site_admin":false},"repo":{"id":45828707,"name":"snappy","full_name":"pedronis/snappy","owner":{"login":"pedronis","id":975757,"avatar_url":"https://avatars.githubusercontent.com/u/975757?v=3","gravatar_id":"","url":"https://api.github.com/users/pedronis","html_url":"https://github.com/pedronis","followers_url":"https://api.github.com/users/pedronis/followers","following_url":"https://api.github.com/users/pedronis/following{/other_user}","gists_url":"https://api.github.com/users/pedronis/gists{/gist_id}","starred_url":"https://api.github.com/users/pedronis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pedronis/subscriptions","organizations_url":"https://api.github.com/users/pedronis/orgs","repos_url":"https://api.github.com/users/pedronis/repos","events_url":"https://api.github.com/users/pedronis/events{/privacy}","received_events_url":"https://api.github.com/users/pedronis/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pedronis/snappy","description":"Snappy is the software at the heart of Ubuntu Core.","fork":true,"url":"https://api.github.com/repos/pedronis/snappy","forks_url":"https://api.github.com/repos/pedronis/snappy/forks","keys_url":"https://api.github.com/repos/pedronis/snappy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pedronis/snappy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pedronis/snappy/teams","hooks_url":"https://api.github.com/repos/pedronis/snappy/hooks","issue_events_url":"https://api.github.com/repos/pedronis/snappy/issues/events{/number}","events_url":"https://api.github.com/repos/pedronis/snappy/events","assignees_url":"https://api.github.com/repos/pedronis/snappy/assignees{/user}","branches_url":"https://api.github.com/repos/pedronis/snappy/branches{/branch}","tags_url":"https://api.github.com/repos/pedronis/snappy/tags","blobs_url":"https://api.github.com/repos/pedronis/snappy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pedronis/snappy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pedronis/snappy/git/refs{/sha}","trees_url":"https://api.github.com/repos/pedronis/snappy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pedronis/snappy/statuses/{sha}","languages_url":"https://api.github.com/repos/pedronis/snappy/languages","stargazers_url":"https://api.github.com/repos/pedronis/snappy/stargazers","contributors_url":"https://api.github.com/repos/pedronis/snappy/contributors","subscribers_url":"https://api.github.com/repos/pedronis/snappy/subscribers","subscription_url":"https://api.github.com/repos/pedronis/snappy/subscription","commits_url":"https://api.github.com/repos/pedronis/snappy/commits{/sha}","git_commits_url":"https://api.github.com/repos/pedronis/snappy/git/commits{/sha}","comments_url":"https://api.github.com/repos/pedronis/snappy/comments{/number}","issue_comment_url":"https://api.github.com/repos/pedronis/snappy/issues/comments{/number}","contents_url":"https://api.github.com/repos/pedronis/snappy/contents/{+path}","compare_url":"https://api.github.com/repos/pedronis/snappy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pedronis/snappy/merges","archive_url":"https://api.github.com/repos/pedronis/snappy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pedronis/snappy/downloads","issues_url":"https://api.github.com/repos/pedronis/snappy/issues{/number}","pulls_url":"https://api.github.com/repos/pedronis/snappy/pulls{/number}","milestones_url":"https://api.github.com/repos/pedronis/snappy/milestones{/number}","notifications_url":"https://api.github.com/repos/pedronis/snappy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pedronis/snappy/labels{/name}","releases_url":"https://api.github.com/repos/pedronis/snappy/releases{/id}","deployments_url":"https://api.github.com/repos/pedronis/snappy/deployments","created_at":"2015-11-09T09:40:46Z","updated_at":"2016-01-13T09:10:26Z","pushed_at":"2016-12-14T22:59:29Z","git_url":"git://github.com/pedronis/snappy.git","ssh_url":"git@github.com:pedronis/snappy.git","clone_url":"https://github.com/pedronis/snappy.git","svn_url":"https://github.com/pedronis/snappy","homepage":null,"size":41149,"stargazers_count":0,"watchers_count":0,"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":0,"default_branch":"master"}},"base":{"label":"snapcore:master","ref":"master","sha":"c327d93a542db99088a1642b22e85cddee5aa936","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":44672744,"name":"snapd","full_name":"snapcore/snapd","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/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":"2016-12-14T19:38:44Z","pushed_at":"2016-12-15T07:40:10Z","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":41140,"stargazers_count":457,"watchers_count":457,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":136,"mirror_url":null,"open_issues_count":44,"forks":136,"open_issues":44,"watchers":457,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/2485"},"html":{"href":"https://github.com/snapcore/snapd/pull/2485"},"issue":{"href":"https://api.github.com/repos/snapcore/snapd/issues/2485"},"comments":{"href":"https://api.github.com/repos/snapcore/snapd/issues/2485/comments"},"review_comments":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/2485/comments"},"review_comment":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/2485/commits"},"statuses":{"href":"https://api.github.com/repos/snapcore/snapd/statuses/71a2346aed03ad688e26e5bca188b6d7287af530"}}}}
{"actor":{"display_login":"mvo5"}}