{"action":"created","comment":{"url":"https://api.github.com/repos/docker/notary/pulls/comments/53052151","id":53052151,"diff_hunk":"@@ -45,44 +45,77 @@ func (c *Client) Update() error {\n \t// 3. Check if root correct against snapshot\n \t//   a. If incorrect, download new root and return to 1.\n \t// 4. Iteratively download and search targets and delegations to find target meta\n+\n+\ttype TufUpdateState int\n+\n+\tconst (\n+\t\tStateDownloadTimestamps TufUpdateState = iota\n+\t\tStateDownloadSnapshots  TufUpdateState = iota\n+\t\tStateDownloadTargets    TufUpdateState = iota\n+\t\tStateCheckRoot          TufUpdateState = iota\n+\t\tStateDownloadRoot       TufUpdateState = iota\n+\t\tStateUpdateComplete     TufUpdateState = iota\n+\t\tStateUpdateFailed       TufUpdateState = iota\n+\t)\n+\n+\tvar err error\n+\tdownloadedRoot := false\n+\tdownloadState := StateDownloadTimestamps\n \tlogrus.Debug(\"updating TUF client\")\n-\terr := c.update()\n-\tif err != nil {\n-\t\tlogrus.Debug(\"Error occurred. Root will be downloaded and another update attempted\")\n-\t\tif err := c.downloadRoot(); err != nil {\n-\t\t\tlogrus.Debug(\"Client Update (Root):\", err)\n-\t\t\treturn err\n-\t\t}\n-\t\t// If we error again, we now have the latest root and just want to fail\n-\t\t// out as there's no expectation the problem can be resolved automatically\n-\t\tlogrus.Debug(\"retrying TUF client update\")\n-\t\treturn c.update()\n-\t}\n-\treturn nil\n-}\n \n-func (c *Client) update() error {\n-\terr := c.downloadTimestamp()\n-\tif err != nil {\n-\t\tlogrus.Debugf(\"Client Update (Timestamp): %s\", err.Error())\n-\t\treturn err\n-\t}\n-\terr = c.downloadSnapshot()\n-\tif err != nil {\n-\t\tlogrus.Debugf(\"Client Update (Snapshot): %s\", err.Error())\n-\t\treturn err\n-\t}\n-\terr = c.checkRoot()\n-\tif err != nil {\n-\t\t// In this instance the root has not expired base on time, but is\n-\t\t// expired based on the snapshot dictating a new root has been produced.\n-\t\tlogrus.Debug(err)\n-\t\treturn err\n+\tfor downloadState != StateUpdateComplete && downloadState != StateUpdateFailed {\n+\t\tswitch downloadState {\n+\t\tcase StateDownloadTimestamps:\n+\t\t\terr = c.downloadTimestamp()\n+\t\t\tif err != nil {\n+\t\t\t\tlogrus.Debugf(\"Client Update (Timestamp): %s\", err.Error())\n+\t\t\t\tdownloadState = StateDownloadRoot\n+\t\t\t\tbreak\n+\t\t\t}\n+\t\t\tdownloadState = StateDownloadSnapshots\n+\t\tcase StateDownloadSnapshots:\n+\t\t\terr = c.downloadSnapshot()\n+\t\t\tif err != nil {\n+\t\t\t\tlogrus.Debugf(\"Client Update (Snapshot): %s\", err.Error())\n+\t\t\t\tdownloadState = StateDownloadRoot\n+\t\t\t\tbreak\n+\t\t\t}\n+\t\t\tdownloadState = StateCheckRoot\n+\t\tcase StateCheckRoot:\n+\t\t\terr = c.checkRoot()\n+\t\t\tif err != nil {\n+\t\t\t\t// In this instance the root has not expired base on time, but is\n+\t\t\t\t// expired based on the snapshot dictating a new root has been produced.\n+\t\t\t\tlogrus.Debug(err)\n+\t\t\t\tdownloadState = StateDownloadRoot\n+\t\t\t\tbreak\n+\t\t\t}\n+\t\t\tdownloadState = StateDownloadTargets\n+\t\tcase StateDownloadTargets:\n+\t\t\t// will always need top level targets at a minimum\n+\t\t\terr = c.downloadTargets(\"targets\")\n+\t\t\tif err != nil {\n+\t\t\t\tlogrus.Debugf(\"Client Update (Targets): %s\", err.Error())\n+\t\t\t\tdownloadState = StateDownloadRoot\n+\t\t\t\tbreak\n+\t\t\t}\n+\t\t\tdownloadState = StateUpdateComplete\n+\t\tcase StateDownloadRoot:\n+\t\t\tif downloadedRoot {\n+\t\t\t\tdownloadState = StateUpdateFailed","path":"tuf/client/client.go","position":92,"original_position":92,"commit_id":"924f6820d1eb8d3fae33c474d78b2995ce6837d7","original_commit_id":"924f6820d1eb8d3fae33c474d78b2995ce6837d7","user":{"login":"diogomonica","id":55332,"avatar_url":"https://avatars.githubusercontent.com/u/55332?v=3","gravatar_id":"","url":"https://api.github.com/users/diogomonica","html_url":"https://github.com/diogomonica","followers_url":"https://api.github.com/users/diogomonica/followers","following_url":"https://api.github.com/users/diogomonica/following{/other_user}","gists_url":"https://api.github.com/users/diogomonica/gists{/gist_id}","starred_url":"https://api.github.com/users/diogomonica/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/diogomonica/subscriptions","organizations_url":"https://api.github.com/users/diogomonica/orgs","repos_url":"https://api.github.com/users/diogomonica/repos","events_url":"https://api.github.com/users/diogomonica/events{/privacy}","received_events_url":"https://api.github.com/users/diogomonica/received_events","type":"User","site_admin":false},"body":"Probably worth adding a debug log on this irrecoverable state.","created_at":"2016-02-16T18:12:12Z","updated_at":"2016-02-16T18:12:12Z","html_url":"https://github.com/docker/notary/pull/570#discussion_r53052151","pull_request_url":"https://api.github.com/repos/docker/notary/pulls/570","_links":{"self":{"href":"https://api.github.com/repos/docker/notary/pulls/comments/53052151"},"html":{"href":"https://github.com/docker/notary/pull/570#discussion_r53052151"},"pull_request":{"href":"https://api.github.com/repos/docker/notary/pulls/570"}}},"pull_request":{"url":"https://api.github.com/repos/docker/notary/pulls/570","id":59309693,"html_url":"https://github.com/docker/notary/pull/570","diff_url":"https://github.com/docker/notary/pull/570.diff","patch_url":"https://github.com/docker/notary/pull/570.patch","issue_url":"https://api.github.com/repos/docker/notary/issues/570","number":570,"state":"open","locked":false,"title":"Client.Update as a simple state machine, logically a no-op","user":{"login":"NathanMcCauley","id":695682,"avatar_url":"https://avatars.githubusercontent.com/u/695682?v=3","gravatar_id":"","url":"https://api.github.com/users/NathanMcCauley","html_url":"https://github.com/NathanMcCauley","followers_url":"https://api.github.com/users/NathanMcCauley/followers","following_url":"https://api.github.com/users/NathanMcCauley/following{/other_user}","gists_url":"https://api.github.com/users/NathanMcCauley/gists{/gist_id}","starred_url":"https://api.github.com/users/NathanMcCauley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NathanMcCauley/subscriptions","organizations_url":"https://api.github.com/users/NathanMcCauley/orgs","repos_url":"https://api.github.com/users/NathanMcCauley/repos","events_url":"https://api.github.com/users/NathanMcCauley/events{/privacy}","received_events_url":"https://api.github.com/users/NathanMcCauley/received_events","type":"User","site_admin":false},"body":"Migrate Client.Update to be a simplistic state machine. More modifications to follow in followup PR where entrance/exit conditions will be modified based on the errors returned from the `Download*()` functions\r\n\r\nSigned-off-by: Nathan McCauley <nathan.mccauley@docker.com>","created_at":"2016-02-14T23:25:54Z","updated_at":"2016-02-16T18:12:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e7ff3c0185add7736d0ca52cf0b580e64be76166","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/docker/notary/pulls/570/commits","review_comments_url":"https://api.github.com/repos/docker/notary/pulls/570/comments","review_comment_url":"https://api.github.com/repos/docker/notary/pulls/comments{/number}","comments_url":"https://api.github.com/repos/docker/notary/issues/570/comments","statuses_url":"https://api.github.com/repos/docker/notary/statuses/924f6820d1eb8d3fae33c474d78b2995ce6837d7","head":{"label":"NathanMcCauley:update-as-state-machine","ref":"update-as-state-machine","sha":"924f6820d1eb8d3fae33c474d78b2995ce6837d7","user":{"login":"NathanMcCauley","id":695682,"avatar_url":"https://avatars.githubusercontent.com/u/695682?v=3","gravatar_id":"","url":"https://api.github.com/users/NathanMcCauley","html_url":"https://github.com/NathanMcCauley","followers_url":"https://api.github.com/users/NathanMcCauley/followers","following_url":"https://api.github.com/users/NathanMcCauley/following{/other_user}","gists_url":"https://api.github.com/users/NathanMcCauley/gists{/gist_id}","starred_url":"https://api.github.com/users/NathanMcCauley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NathanMcCauley/subscriptions","organizations_url":"https://api.github.com/users/NathanMcCauley/orgs","repos_url":"https://api.github.com/users/NathanMcCauley/repos","events_url":"https://api.github.com/users/NathanMcCauley/events{/privacy}","received_events_url":"https://api.github.com/users/NathanMcCauley/received_events","type":"User","site_admin":false},"repo":{"id":49683529,"name":"notary","full_name":"NathanMcCauley/notary","owner":{"login":"NathanMcCauley","id":695682,"avatar_url":"https://avatars.githubusercontent.com/u/695682?v=3","gravatar_id":"","url":"https://api.github.com/users/NathanMcCauley","html_url":"https://github.com/NathanMcCauley","followers_url":"https://api.github.com/users/NathanMcCauley/followers","following_url":"https://api.github.com/users/NathanMcCauley/following{/other_user}","gists_url":"https://api.github.com/users/NathanMcCauley/gists{/gist_id}","starred_url":"https://api.github.com/users/NathanMcCauley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NathanMcCauley/subscriptions","organizations_url":"https://api.github.com/users/NathanMcCauley/orgs","repos_url":"https://api.github.com/users/NathanMcCauley/repos","events_url":"https://api.github.com/users/NathanMcCauley/events{/privacy}","received_events_url":"https://api.github.com/users/NathanMcCauley/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/NathanMcCauley/notary","description":"Notary is a Docker project that allows anyone to have trust over arbitrary collections of data","fork":true,"url":"https://api.github.com/repos/NathanMcCauley/notary","forks_url":"https://api.github.com/repos/NathanMcCauley/notary/forks","keys_url":"https://api.github.com/repos/NathanMcCauley/notary/keys{/key_id}","collaborators_url":"https://api.github.com/repos/NathanMcCauley/notary/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/NathanMcCauley/notary/teams","hooks_url":"https://api.github.com/repos/NathanMcCauley/notary/hooks","issue_events_url":"https://api.github.com/repos/NathanMcCauley/notary/issues/events{/number}","events_url":"https://api.github.com/repos/NathanMcCauley/notary/events","assignees_url":"https://api.github.com/repos/NathanMcCauley/notary/assignees{/user}","branches_url":"https://api.github.com/repos/NathanMcCauley/notary/branches{/branch}","tags_url":"https://api.github.com/repos/NathanMcCauley/notary/tags","blobs_url":"https://api.github.com/repos/NathanMcCauley/notary/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/NathanMcCauley/notary/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/NathanMcCauley/notary/git/refs{/sha}","trees_url":"https://api.github.com/repos/NathanMcCauley/notary/git/trees{/sha}","statuses_url":"https://api.github.com/repos/NathanMcCauley/notary/statuses/{sha}","languages_url":"https://api.github.com/repos/NathanMcCauley/notary/languages","stargazers_url":"https://api.github.com/repos/NathanMcCauley/notary/stargazers","contributors_url":"https://api.github.com/repos/NathanMcCauley/notary/contributors","subscribers_url":"https://api.github.com/repos/NathanMcCauley/notary/subscribers","subscription_url":"https://api.github.com/repos/NathanMcCauley/notary/subscription","commits_url":"https://api.github.com/repos/NathanMcCauley/notary/commits{/sha}","git_commits_url":"https://api.github.com/repos/NathanMcCauley/notary/git/commits{/sha}","comments_url":"https://api.github.com/repos/NathanMcCauley/notary/comments{/number}","issue_comment_url":"https://api.github.com/repos/NathanMcCauley/notary/issues/comments{/number}","contents_url":"https://api.github.com/repos/NathanMcCauley/notary/contents/{+path}","compare_url":"https://api.github.com/repos/NathanMcCauley/notary/compare/{base}...{head}","merges_url":"https://api.github.com/repos/NathanMcCauley/notary/merges","archive_url":"https://api.github.com/repos/NathanMcCauley/notary/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/NathanMcCauley/notary/downloads","issues_url":"https://api.github.com/repos/NathanMcCauley/notary/issues{/number}","pulls_url":"https://api.github.com/repos/NathanMcCauley/notary/pulls{/number}","milestones_url":"https://api.github.com/repos/NathanMcCauley/notary/milestones{/number}","notifications_url":"https://api.github.com/repos/NathanMcCauley/notary/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/NathanMcCauley/notary/labels{/name}","releases_url":"https://api.github.com/repos/NathanMcCauley/notary/releases{/id}","deployments_url":"https://api.github.com/repos/NathanMcCauley/notary/deployments","created_at":"2016-01-15T00:02:44Z","updated_at":"2016-01-15T00:02:45Z","pushed_at":"2016-02-14T23:33:07Z","git_url":"git://github.com/NathanMcCauley/notary.git","ssh_url":"git@github.com:NathanMcCauley/notary.git","clone_url":"https://github.com/NathanMcCauley/notary.git","svn_url":"https://github.com/NathanMcCauley/notary","homepage":"https://docker.com","size":22890,"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":"docker:master","ref":"master","sha":"9010989a208abd414e0ab01e5a772045937a6098","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":37743436,"name":"notary","full_name":"docker/notary","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/notary","description":"Notary is a Docker project that allows anyone to have trust over arbitrary collections of data","fork":false,"url":"https://api.github.com/repos/docker/notary","forks_url":"https://api.github.com/repos/docker/notary/forks","keys_url":"https://api.github.com/repos/docker/notary/keys{/key_id}","collaborators_url":"https://api.github.com/repos/docker/notary/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/docker/notary/teams","hooks_url":"https://api.github.com/repos/docker/notary/hooks","issue_events_url":"https://api.github.com/repos/docker/notary/issues/events{/number}","events_url":"https://api.github.com/repos/docker/notary/events","assignees_url":"https://api.github.com/repos/docker/notary/assignees{/user}","branches_url":"https://api.github.com/repos/docker/notary/branches{/branch}","tags_url":"https://api.github.com/repos/docker/notary/tags","blobs_url":"https://api.github.com/repos/docker/notary/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/docker/notary/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/docker/notary/git/refs{/sha}","trees_url":"https://api.github.com/repos/docker/notary/git/trees{/sha}","statuses_url":"https://api.github.com/repos/docker/notary/statuses/{sha}","languages_url":"https://api.github.com/repos/docker/notary/languages","stargazers_url":"https://api.github.com/repos/docker/notary/stargazers","contributors_url":"https://api.github.com/repos/docker/notary/contributors","subscribers_url":"https://api.github.com/repos/docker/notary/subscribers","subscription_url":"https://api.github.com/repos/docker/notary/subscription","commits_url":"https://api.github.com/repos/docker/notary/commits{/sha}","git_commits_url":"https://api.github.com/repos/docker/notary/git/commits{/sha}","comments_url":"https://api.github.com/repos/docker/notary/comments{/number}","issue_comment_url":"https://api.github.com/repos/docker/notary/issues/comments{/number}","contents_url":"https://api.github.com/repos/docker/notary/contents/{+path}","compare_url":"https://api.github.com/repos/docker/notary/compare/{base}...{head}","merges_url":"https://api.github.com/repos/docker/notary/merges","archive_url":"https://api.github.com/repos/docker/notary/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/docker/notary/downloads","issues_url":"https://api.github.com/repos/docker/notary/issues{/number}","pulls_url":"https://api.github.com/repos/docker/notary/pulls{/number}","milestones_url":"https://api.github.com/repos/docker/notary/milestones{/number}","notifications_url":"https://api.github.com/repos/docker/notary/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/docker/notary/labels{/name}","releases_url":"https://api.github.com/repos/docker/notary/releases{/id}","deployments_url":"https://api.github.com/repos/docker/notary/deployments","created_at":"2015-06-19T20:07:53Z","updated_at":"2016-02-16T00:43:01Z","pushed_at":"2016-02-16T18:07:09Z","git_url":"git://github.com/docker/notary.git","ssh_url":"git@github.com:docker/notary.git","clone_url":"https://github.com/docker/notary.git","svn_url":"https://github.com/docker/notary","homepage":"https://docker.com","size":24147,"stargazers_count":479,"watchers_count":479,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":73,"mirror_url":null,"open_issues_count":90,"forks":73,"open_issues":90,"watchers":479,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/docker/notary/pulls/570"},"html":{"href":"https://github.com/docker/notary/pull/570"},"issue":{"href":"https://api.github.com/repos/docker/notary/issues/570"},"comments":{"href":"https://api.github.com/repos/docker/notary/issues/570/comments"},"review_comments":{"href":"https://api.github.com/repos/docker/notary/pulls/570/comments"},"review_comment":{"href":"https://api.github.com/repos/docker/notary/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/docker/notary/pulls/570/commits"},"statuses":{"href":"https://api.github.com/repos/docker/notary/statuses/924f6820d1eb8d3fae33c474d78b2995ce6837d7"}}}}