{"action":"created","comment":{"url":"https://api.github.com/repos/xapi-project/xen-api/pulls/comments/176035010","pull_request_review_id":105662666,"id":176035010,"diff_hunk":"@@ -90,6 +89,48 @@ def get_cg_dir(domid):\n     return \"/sys/fs/cgroup/devices/qemu-{}\".format(domid)\n \n \n+def get_ids_path(device):\n+    usb_dir = \"/var/run/nonpersistent/usb\"\n+    if not os.path.isdir(usb_dir):\n+        os.makedirs(usb_dir)\n+    return usb_dir + \"/{}\".format(device)\n+\n+\n+def save_device_ids(device):\n+    path = dev_path(device)\n+\n+    try:\n+        stat = os.stat(path)\n+        ids_info = \"{} {}\".format(stat.st_uid, stat.st_gid)\n+    except OSError as e:\n+        log.error(\"Failed to get stat of file {}: {}\".format(path, str(e)))\n+        exit(1)\n+\n+    try:\n+        with open(get_ids_path(device), \"w\") as f:\n+            f.write(ids_info)\n+    except IOError as e:\n+        log.error(\"Failed to save of file ids {}: {}\".format(path, str(e)))\n+        exit(1)\n+\n+\n+def restore_device_ids(device):\n+    ids_path = get_ids_path(device)\n+    try:\n+        with open(ids_path) as f:\n+            uid, gid = map(int, f.readline().split())","path":"scripts/usb_reset.py","position":67,"original_position":67,"commit_id":"0e0d3cd2eb48e3a961a86147f888b19c7054ef2c","original_commit_id":"0e0d3cd2eb48e3a961a86147f888b19c7054ef2c","user":{"login":"rosslagerwall","id":878055,"avatar_url":"https://avatars0.githubusercontent.com/u/878055?v=4","gravatar_id":"","url":"https://api.github.com/users/rosslagerwall","html_url":"https://github.com/rosslagerwall","followers_url":"https://api.github.com/users/rosslagerwall/followers","following_url":"https://api.github.com/users/rosslagerwall/following{/other_user}","gists_url":"https://api.github.com/users/rosslagerwall/gists{/gist_id}","starred_url":"https://api.github.com/users/rosslagerwall/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rosslagerwall/subscriptions","organizations_url":"https://api.github.com/users/rosslagerwall/orgs","repos_url":"https://api.github.com/users/rosslagerwall/repos","events_url":"https://api.github.com/users/rosslagerwall/events{/privacy}","received_events_url":"https://api.github.com/users/rosslagerwall/received_events","type":"User","site_admin":false},"body":"You can just use `read()` instead of `readline()`... since you don't actually write a newline previously.","created_at":"2018-03-21T10:26:22Z","updated_at":"2018-03-21T10:27:44Z","html_url":"https://github.com/xapi-project/xen-api/pull/3525#discussion_r176035010","pull_request_url":"https://api.github.com/repos/xapi-project/xen-api/pulls/3525","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/xapi-project/xen-api/pulls/comments/176035010"},"html":{"href":"https://github.com/xapi-project/xen-api/pull/3525#discussion_r176035010"},"pull_request":{"href":"https://api.github.com/repos/xapi-project/xen-api/pulls/3525"}}},"pull_request":{"url":"https://api.github.com/repos/xapi-project/xen-api/pulls/3525","id":176114466,"html_url":"https://github.com/xapi-project/xen-api/pull/3525","diff_url":"https://github.com/xapi-project/xen-api/pull/3525.diff","patch_url":"https://github.com/xapi-project/xen-api/pull/3525.patch","issue_url":"https://api.github.com/repos/xapi-project/xen-api/issues/3525","number":3525,"state":"open","locked":false,"title":"CP-27452: return uid/gid of device file","user":{"login":"TalonsLee","id":7933910,"avatar_url":"https://avatars2.githubusercontent.com/u/7933910?v=4","gravatar_id":"","url":"https://api.github.com/users/TalonsLee","html_url":"https://github.com/TalonsLee","followers_url":"https://api.github.com/users/TalonsLee/followers","following_url":"https://api.github.com/users/TalonsLee/following{/other_user}","gists_url":"https://api.github.com/users/TalonsLee/gists{/gist_id}","starred_url":"https://api.github.com/users/TalonsLee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TalonsLee/subscriptions","organizations_url":"https://api.github.com/users/TalonsLee/orgs","repos_url":"https://api.github.com/users/TalonsLee/repos","events_url":"https://api.github.com/users/TalonsLee/events{/privacy}","received_events_url":"https://api.github.com/users/TalonsLee/received_events","type":"User","site_admin":false},"body":"return the uid/gid of device file when attaching device, these ids\r\nshould be restored later.","created_at":"2018-03-20T08:10:11Z","updated_at":"2018-03-21T10:27:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"de6c37eb36272ce447598da9bf4766e1390bd1b1","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/xapi-project/xen-api/pulls/3525/commits","review_comments_url":"https://api.github.com/repos/xapi-project/xen-api/pulls/3525/comments","review_comment_url":"https://api.github.com/repos/xapi-project/xen-api/pulls/comments{/number}","comments_url":"https://api.github.com/repos/xapi-project/xen-api/issues/3525/comments","statuses_url":"https://api.github.com/repos/xapi-project/xen-api/statuses/0e0d3cd2eb48e3a961a86147f888b19c7054ef2c","head":{"label":"TalonsLee:CP-27452","ref":"CP-27452","sha":"0e0d3cd2eb48e3a961a86147f888b19c7054ef2c","user":{"login":"TalonsLee","id":7933910,"avatar_url":"https://avatars2.githubusercontent.com/u/7933910?v=4","gravatar_id":"","url":"https://api.github.com/users/TalonsLee","html_url":"https://github.com/TalonsLee","followers_url":"https://api.github.com/users/TalonsLee/followers","following_url":"https://api.github.com/users/TalonsLee/following{/other_user}","gists_url":"https://api.github.com/users/TalonsLee/gists{/gist_id}","starred_url":"https://api.github.com/users/TalonsLee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TalonsLee/subscriptions","organizations_url":"https://api.github.com/users/TalonsLee/orgs","repos_url":"https://api.github.com/users/TalonsLee/repos","events_url":"https://api.github.com/users/TalonsLee/events{/privacy}","received_events_url":"https://api.github.com/users/TalonsLee/received_events","type":"User","site_admin":false},"repo":{"id":104173422,"name":"xen-api","full_name":"TalonsLee/xen-api","owner":{"login":"TalonsLee","id":7933910,"avatar_url":"https://avatars2.githubusercontent.com/u/7933910?v=4","gravatar_id":"","url":"https://api.github.com/users/TalonsLee","html_url":"https://github.com/TalonsLee","followers_url":"https://api.github.com/users/TalonsLee/followers","following_url":"https://api.github.com/users/TalonsLee/following{/other_user}","gists_url":"https://api.github.com/users/TalonsLee/gists{/gist_id}","starred_url":"https://api.github.com/users/TalonsLee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TalonsLee/subscriptions","organizations_url":"https://api.github.com/users/TalonsLee/orgs","repos_url":"https://api.github.com/users/TalonsLee/repos","events_url":"https://api.github.com/users/TalonsLee/events{/privacy}","received_events_url":"https://api.github.com/users/TalonsLee/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/TalonsLee/xen-api","description":"The Xapi Project's XenAPI Server","fork":true,"url":"https://api.github.com/repos/TalonsLee/xen-api","forks_url":"https://api.github.com/repos/TalonsLee/xen-api/forks","keys_url":"https://api.github.com/repos/TalonsLee/xen-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/TalonsLee/xen-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/TalonsLee/xen-api/teams","hooks_url":"https://api.github.com/repos/TalonsLee/xen-api/hooks","issue_events_url":"https://api.github.com/repos/TalonsLee/xen-api/issues/events{/number}","events_url":"https://api.github.com/repos/TalonsLee/xen-api/events","assignees_url":"https://api.github.com/repos/TalonsLee/xen-api/assignees{/user}","branches_url":"https://api.github.com/repos/TalonsLee/xen-api/branches{/branch}","tags_url":"https://api.github.com/repos/TalonsLee/xen-api/tags","blobs_url":"https://api.github.com/repos/TalonsLee/xen-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/TalonsLee/xen-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/TalonsLee/xen-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/TalonsLee/xen-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/TalonsLee/xen-api/statuses/{sha}","languages_url":"https://api.github.com/repos/TalonsLee/xen-api/languages","stargazers_url":"https://api.github.com/repos/TalonsLee/xen-api/stargazers","contributors_url":"https://api.github.com/repos/TalonsLee/xen-api/contributors","subscribers_url":"https://api.github.com/repos/TalonsLee/xen-api/subscribers","subscription_url":"https://api.github.com/repos/TalonsLee/xen-api/subscription","commits_url":"https://api.github.com/repos/TalonsLee/xen-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/TalonsLee/xen-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/TalonsLee/xen-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/TalonsLee/xen-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/TalonsLee/xen-api/contents/{+path}","compare_url":"https://api.github.com/repos/TalonsLee/xen-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/TalonsLee/xen-api/merges","archive_url":"https://api.github.com/repos/TalonsLee/xen-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/TalonsLee/xen-api/downloads","issues_url":"https://api.github.com/repos/TalonsLee/xen-api/issues{/number}","pulls_url":"https://api.github.com/repos/TalonsLee/xen-api/pulls{/number}","milestones_url":"https://api.github.com/repos/TalonsLee/xen-api/milestones{/number}","notifications_url":"https://api.github.com/repos/TalonsLee/xen-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/TalonsLee/xen-api/labels{/name}","releases_url":"https://api.github.com/repos/TalonsLee/xen-api/releases{/id}","deployments_url":"https://api.github.com/repos/TalonsLee/xen-api/deployments","created_at":"2017-09-20T06:11:09Z","updated_at":"2017-09-20T06:11:14Z","pushed_at":"2018-03-21T06:23:04Z","git_url":"git://github.com/TalonsLee/xen-api.git","ssh_url":"git@github.com:TalonsLee/xen-api.git","clone_url":"https://github.com/TalonsLee/xen-api.git","svn_url":"https://github.com/TalonsLee/xen-api","homepage":"http://xenproject.org/developers/teams/xapi.html","size":31348,"stargazers_count":0,"watchers_count":0,"language":"OCaml","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":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"xapi-project:qemu-stable","ref":"qemu-stable","sha":"b88a54e811dc6a0ede43c930a88333dcdcfd4845","user":{"login":"xapi-project","id":317268,"avatar_url":"https://avatars3.githubusercontent.com/u/317268?v=4","gravatar_id":"","url":"https://api.github.com/users/xapi-project","html_url":"https://github.com/xapi-project","followers_url":"https://api.github.com/users/xapi-project/followers","following_url":"https://api.github.com/users/xapi-project/following{/other_user}","gists_url":"https://api.github.com/users/xapi-project/gists{/gist_id}","starred_url":"https://api.github.com/users/xapi-project/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xapi-project/subscriptions","organizations_url":"https://api.github.com/users/xapi-project/orgs","repos_url":"https://api.github.com/users/xapi-project/repos","events_url":"https://api.github.com/users/xapi-project/events{/privacy}","received_events_url":"https://api.github.com/users/xapi-project/received_events","type":"Organization","site_admin":false},"repo":{"id":960233,"name":"xen-api","full_name":"xapi-project/xen-api","owner":{"login":"xapi-project","id":317268,"avatar_url":"https://avatars3.githubusercontent.com/u/317268?v=4","gravatar_id":"","url":"https://api.github.com/users/xapi-project","html_url":"https://github.com/xapi-project","followers_url":"https://api.github.com/users/xapi-project/followers","following_url":"https://api.github.com/users/xapi-project/following{/other_user}","gists_url":"https://api.github.com/users/xapi-project/gists{/gist_id}","starred_url":"https://api.github.com/users/xapi-project/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xapi-project/subscriptions","organizations_url":"https://api.github.com/users/xapi-project/orgs","repos_url":"https://api.github.com/users/xapi-project/repos","events_url":"https://api.github.com/users/xapi-project/events{/privacy}","received_events_url":"https://api.github.com/users/xapi-project/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/xapi-project/xen-api","description":"The Xapi Project's XenAPI Server","fork":false,"url":"https://api.github.com/repos/xapi-project/xen-api","forks_url":"https://api.github.com/repos/xapi-project/xen-api/forks","keys_url":"https://api.github.com/repos/xapi-project/xen-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/xapi-project/xen-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/xapi-project/xen-api/teams","hooks_url":"https://api.github.com/repos/xapi-project/xen-api/hooks","issue_events_url":"https://api.github.com/repos/xapi-project/xen-api/issues/events{/number}","events_url":"https://api.github.com/repos/xapi-project/xen-api/events","assignees_url":"https://api.github.com/repos/xapi-project/xen-api/assignees{/user}","branches_url":"https://api.github.com/repos/xapi-project/xen-api/branches{/branch}","tags_url":"https://api.github.com/repos/xapi-project/xen-api/tags","blobs_url":"https://api.github.com/repos/xapi-project/xen-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/xapi-project/xen-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/xapi-project/xen-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/xapi-project/xen-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/xapi-project/xen-api/statuses/{sha}","languages_url":"https://api.github.com/repos/xapi-project/xen-api/languages","stargazers_url":"https://api.github.com/repos/xapi-project/xen-api/stargazers","contributors_url":"https://api.github.com/repos/xapi-project/xen-api/contributors","subscribers_url":"https://api.github.com/repos/xapi-project/xen-api/subscribers","subscription_url":"https://api.github.com/repos/xapi-project/xen-api/subscription","commits_url":"https://api.github.com/repos/xapi-project/xen-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/xapi-project/xen-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/xapi-project/xen-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/xapi-project/xen-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/xapi-project/xen-api/contents/{+path}","compare_url":"https://api.github.com/repos/xapi-project/xen-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/xapi-project/xen-api/merges","archive_url":"https://api.github.com/repos/xapi-project/xen-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/xapi-project/xen-api/downloads","issues_url":"https://api.github.com/repos/xapi-project/xen-api/issues{/number}","pulls_url":"https://api.github.com/repos/xapi-project/xen-api/pulls{/number}","milestones_url":"https://api.github.com/repos/xapi-project/xen-api/milestones{/number}","notifications_url":"https://api.github.com/repos/xapi-project/xen-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/xapi-project/xen-api/labels{/name}","releases_url":"https://api.github.com/repos/xapi-project/xen-api/releases{/id}","deployments_url":"https://api.github.com/repos/xapi-project/xen-api/deployments","created_at":"2010-10-04T10:52:57Z","updated_at":"2018-03-20T10:57:52Z","pushed_at":"2018-03-21T07:46:10Z","git_url":"git://github.com/xapi-project/xen-api.git","ssh_url":"git@github.com:xapi-project/xen-api.git","clone_url":"https://github.com/xapi-project/xen-api.git","svn_url":"https://github.com/xapi-project/xen-api","homepage":"http://xenproject.org/developers/teams/xapi.html","size":32487,"stargazers_count":254,"watchers_count":254,"language":"OCaml","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":204,"mirror_url":null,"archived":false,"open_issues_count":17,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":204,"open_issues":17,"watchers":254,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/xapi-project/xen-api/pulls/3525"},"html":{"href":"https://github.com/xapi-project/xen-api/pull/3525"},"issue":{"href":"https://api.github.com/repos/xapi-project/xen-api/issues/3525"},"comments":{"href":"https://api.github.com/repos/xapi-project/xen-api/issues/3525/comments"},"review_comments":{"href":"https://api.github.com/repos/xapi-project/xen-api/pulls/3525/comments"},"review_comment":{"href":"https://api.github.com/repos/xapi-project/xen-api/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/xapi-project/xen-api/pulls/3525/commits"},"statuses":{"href":"https://api.github.com/repos/xapi-project/xen-api/statuses/0e0d3cd2eb48e3a961a86147f888b19c7054ef2c"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"rosslagerwall"}}