{"action":"created","comment":{"url":"https://api.github.com/repos/rminnich/u-root/pulls/comments/38255840","id":38255840,"diff_hunk":"@@ -12,18 +12,50 @@ package main\n import (\n \t\"flag\"\n \t\"fmt\"\n+\t\"log\"\n \t\"os\"\n+\t\"path\"\n )\n \n+func usage() {\n+\tfmt.Printf(\"usage: mv source target\\n\")\n+\tfmt.Printf(\"       mv source ... directory\\n\")\n+\tos.Exit(1)\n+}\n+\n func main() {\n+\ttodir := false\n \tflag.Parse()\n-\ta := flag.Args()\n-\tif len(a) < 2 {\n-\t\tfmt.Printf(\"mv - missing file operand\\n\")\n+\n+\tif flag.NArg() < 2 {\n+\t\tusage()\n+\t}\n+\n+\tfiles := flag.Args()\n+\tlf := files[len(files)-1]\n+\tlfdir, err := os.Stat(lf)\n+\tif err == nil {\n+\t\ttodir = lfdir.IsDir()\n+\t}\n+\tif flag.NArg() > 2 && todir == false {\n+\t\tfmt.Printf(\"not a directory: %s\\n\", lf)\n+\t\tos.Exit(1)\n+\t}\n+\n+\tif len(files) == 2 && todir == false {\n+\t\t// rename file\n+\t\terr := os.Rename(files[0], files[1])","path":"src/cmds/mv/mv.go","position":39,"original_position":39,"commit_id":"b05ec3382f78dd4bba398ecc8dcd80308805bcc2","original_commit_id":"b05ec3382f78dd4bba398ecc8dcd80308805bcc2","user":{"login":"mirtchovski","id":2047078,"avatar_url":"https://avatars.githubusercontent.com/u/2047078?v=3","gravatar_id":"","url":"https://api.github.com/users/mirtchovski","html_url":"https://github.com/mirtchovski","followers_url":"https://api.github.com/users/mirtchovski/followers","following_url":"https://api.github.com/users/mirtchovski/following{/other_user}","gists_url":"https://api.github.com/users/mirtchovski/gists{/gist_id}","starred_url":"https://api.github.com/users/mirtchovski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mirtchovski/subscriptions","organizations_url":"https://api.github.com/users/mirtchovski/orgs","repos_url":"https://api.github.com/users/mirtchovski/repos","events_url":"https://api.github.com/users/mirtchovski/events{/privacy}","received_events_url":"https://api.github.com/users/mirtchovski/received_events","type":"User","site_admin":false},"body":"you're missing a check that the two files are identical here. (samefile in plan9's mv.c, but it will be useless to you). it's probably not ok to just compare paths, you'll need to resolve links and do `Realpath` equivalent on the \"from\"","created_at":"2015-08-29T00:15:47Z","updated_at":"2015-08-29T00:15:47Z","html_url":"https://github.com/rminnich/u-root/pull/15#discussion_r38255840","pull_request_url":"https://api.github.com/repos/rminnich/u-root/pulls/15","_links":{"self":{"href":"https://api.github.com/repos/rminnich/u-root/pulls/comments/38255840"},"html":{"href":"https://github.com/rminnich/u-root/pull/15#discussion_r38255840"},"pull_request":{"href":"https://api.github.com/repos/rminnich/u-root/pulls/15"}}},"pull_request":{"url":"https://api.github.com/repos/rminnich/u-root/pulls/15","id":43677524,"html_url":"https://github.com/rminnich/u-root/pull/15","diff_url":"https://github.com/rminnich/u-root/pull/15.diff","patch_url":"https://github.com/rminnich/u-root/pull/15.patch","issue_url":"https://api.github.com/repos/rminnich/u-root/issues/15","number":15,"state":"open","locked":false,"title":"New version of \"mv.go\"","user":{"login":"rhiguita","id":5674789,"avatar_url":"https://avatars.githubusercontent.com/u/5674789?v=3","gravatar_id":"","url":"https://api.github.com/users/rhiguita","html_url":"https://github.com/rhiguita","followers_url":"https://api.github.com/users/rhiguita/followers","following_url":"https://api.github.com/users/rhiguita/following{/other_user}","gists_url":"https://api.github.com/users/rhiguita/gists{/gist_id}","starred_url":"https://api.github.com/users/rhiguita/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rhiguita/subscriptions","organizations_url":"https://api.github.com/users/rhiguita/orgs","repos_url":"https://api.github.com/users/rhiguita/repos","events_url":"https://api.github.com/users/rhiguita/events{/privacy}","received_events_url":"https://api.github.com/users/rhiguita/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-08-28T22:15:39Z","updated_at":"2015-08-29T00:15:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ad081e09389adf5daf5ad2caed5d7698da1273f6","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/rminnich/u-root/pulls/15/commits","review_comments_url":"https://api.github.com/repos/rminnich/u-root/pulls/15/comments","review_comment_url":"https://api.github.com/repos/rminnich/u-root/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rminnich/u-root/issues/15/comments","statuses_url":"https://api.github.com/repos/rminnich/u-root/statuses/b05ec3382f78dd4bba398ecc8dcd80308805bcc2","head":{"label":"rhiguita:master","ref":"master","sha":"b05ec3382f78dd4bba398ecc8dcd80308805bcc2","user":{"login":"rhiguita","id":5674789,"avatar_url":"https://avatars.githubusercontent.com/u/5674789?v=3","gravatar_id":"","url":"https://api.github.com/users/rhiguita","html_url":"https://github.com/rhiguita","followers_url":"https://api.github.com/users/rhiguita/followers","following_url":"https://api.github.com/users/rhiguita/following{/other_user}","gists_url":"https://api.github.com/users/rhiguita/gists{/gist_id}","starred_url":"https://api.github.com/users/rhiguita/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rhiguita/subscriptions","organizations_url":"https://api.github.com/users/rhiguita/orgs","repos_url":"https://api.github.com/users/rhiguita/repos","events_url":"https://api.github.com/users/rhiguita/events{/privacy}","received_events_url":"https://api.github.com/users/rhiguita/received_events","type":"User","site_admin":false},"repo":{"id":41001685,"name":"u-root","full_name":"rhiguita/u-root","owner":{"login":"rhiguita","id":5674789,"avatar_url":"https://avatars.githubusercontent.com/u/5674789?v=3","gravatar_id":"","url":"https://api.github.com/users/rhiguita","html_url":"https://github.com/rhiguita","followers_url":"https://api.github.com/users/rhiguita/followers","following_url":"https://api.github.com/users/rhiguita/following{/other_user}","gists_url":"https://api.github.com/users/rhiguita/gists{/gist_id}","starred_url":"https://api.github.com/users/rhiguita/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rhiguita/subscriptions","organizations_url":"https://api.github.com/users/rhiguita/orgs","repos_url":"https://api.github.com/users/rhiguita/repos","events_url":"https://api.github.com/users/rhiguita/events{/privacy}","received_events_url":"https://api.github.com/users/rhiguita/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rhiguita/u-root","description":"A universal root. You mount it, and it's mostly Go source with the exception of 5 binaries. ","fork":true,"url":"https://api.github.com/repos/rhiguita/u-root","forks_url":"https://api.github.com/repos/rhiguita/u-root/forks","keys_url":"https://api.github.com/repos/rhiguita/u-root/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rhiguita/u-root/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rhiguita/u-root/teams","hooks_url":"https://api.github.com/repos/rhiguita/u-root/hooks","issue_events_url":"https://api.github.com/repos/rhiguita/u-root/issues/events{/number}","events_url":"https://api.github.com/repos/rhiguita/u-root/events","assignees_url":"https://api.github.com/repos/rhiguita/u-root/assignees{/user}","branches_url":"https://api.github.com/repos/rhiguita/u-root/branches{/branch}","tags_url":"https://api.github.com/repos/rhiguita/u-root/tags","blobs_url":"https://api.github.com/repos/rhiguita/u-root/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rhiguita/u-root/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rhiguita/u-root/git/refs{/sha}","trees_url":"https://api.github.com/repos/rhiguita/u-root/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rhiguita/u-root/statuses/{sha}","languages_url":"https://api.github.com/repos/rhiguita/u-root/languages","stargazers_url":"https://api.github.com/repos/rhiguita/u-root/stargazers","contributors_url":"https://api.github.com/repos/rhiguita/u-root/contributors","subscribers_url":"https://api.github.com/repos/rhiguita/u-root/subscribers","subscription_url":"https://api.github.com/repos/rhiguita/u-root/subscription","commits_url":"https://api.github.com/repos/rhiguita/u-root/commits{/sha}","git_commits_url":"https://api.github.com/repos/rhiguita/u-root/git/commits{/sha}","comments_url":"https://api.github.com/repos/rhiguita/u-root/comments{/number}","issue_comment_url":"https://api.github.com/repos/rhiguita/u-root/issues/comments{/number}","contents_url":"https://api.github.com/repos/rhiguita/u-root/contents/{+path}","compare_url":"https://api.github.com/repos/rhiguita/u-root/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rhiguita/u-root/merges","archive_url":"https://api.github.com/repos/rhiguita/u-root/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rhiguita/u-root/downloads","issues_url":"https://api.github.com/repos/rhiguita/u-root/issues{/number}","pulls_url":"https://api.github.com/repos/rhiguita/u-root/pulls{/number}","milestones_url":"https://api.github.com/repos/rhiguita/u-root/milestones{/number}","notifications_url":"https://api.github.com/repos/rhiguita/u-root/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rhiguita/u-root/labels{/name}","releases_url":"https://api.github.com/repos/rhiguita/u-root/releases{/id}","created_at":"2015-08-18T23:02:35Z","updated_at":"2015-08-18T23:02:37Z","pushed_at":"2015-08-28T22:15:57Z","git_url":"git://github.com/rhiguita/u-root.git","ssh_url":"git@github.com:rhiguita/u-root.git","clone_url":"https://github.com/rhiguita/u-root.git","svn_url":"https://github.com/rhiguita/u-root","homepage":null,"size":10211,"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":"rminnich:master","ref":"master","sha":"94825222357ec4b0c74a9162b425bfd9f5989c15","user":{"login":"rminnich","id":74928,"avatar_url":"https://avatars.githubusercontent.com/u/74928?v=3","gravatar_id":"","url":"https://api.github.com/users/rminnich","html_url":"https://github.com/rminnich","followers_url":"https://api.github.com/users/rminnich/followers","following_url":"https://api.github.com/users/rminnich/following{/other_user}","gists_url":"https://api.github.com/users/rminnich/gists{/gist_id}","starred_url":"https://api.github.com/users/rminnich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rminnich/subscriptions","organizations_url":"https://api.github.com/users/rminnich/orgs","repos_url":"https://api.github.com/users/rminnich/repos","events_url":"https://api.github.com/users/rminnich/events{/privacy}","received_events_url":"https://api.github.com/users/rminnich/received_events","type":"User","site_admin":false},"repo":{"id":6444385,"name":"u-root","full_name":"rminnich/u-root","owner":{"login":"rminnich","id":74928,"avatar_url":"https://avatars.githubusercontent.com/u/74928?v=3","gravatar_id":"","url":"https://api.github.com/users/rminnich","html_url":"https://github.com/rminnich","followers_url":"https://api.github.com/users/rminnich/followers","following_url":"https://api.github.com/users/rminnich/following{/other_user}","gists_url":"https://api.github.com/users/rminnich/gists{/gist_id}","starred_url":"https://api.github.com/users/rminnich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rminnich/subscriptions","organizations_url":"https://api.github.com/users/rminnich/orgs","repos_url":"https://api.github.com/users/rminnich/repos","events_url":"https://api.github.com/users/rminnich/events{/privacy}","received_events_url":"https://api.github.com/users/rminnich/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rminnich/u-root","description":"A universal root. You mount it, and it's mostly Go source with the exception of 5 binaries. ","fork":false,"url":"https://api.github.com/repos/rminnich/u-root","forks_url":"https://api.github.com/repos/rminnich/u-root/forks","keys_url":"https://api.github.com/repos/rminnich/u-root/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rminnich/u-root/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rminnich/u-root/teams","hooks_url":"https://api.github.com/repos/rminnich/u-root/hooks","issue_events_url":"https://api.github.com/repos/rminnich/u-root/issues/events{/number}","events_url":"https://api.github.com/repos/rminnich/u-root/events","assignees_url":"https://api.github.com/repos/rminnich/u-root/assignees{/user}","branches_url":"https://api.github.com/repos/rminnich/u-root/branches{/branch}","tags_url":"https://api.github.com/repos/rminnich/u-root/tags","blobs_url":"https://api.github.com/repos/rminnich/u-root/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rminnich/u-root/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rminnich/u-root/git/refs{/sha}","trees_url":"https://api.github.com/repos/rminnich/u-root/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rminnich/u-root/statuses/{sha}","languages_url":"https://api.github.com/repos/rminnich/u-root/languages","stargazers_url":"https://api.github.com/repos/rminnich/u-root/stargazers","contributors_url":"https://api.github.com/repos/rminnich/u-root/contributors","subscribers_url":"https://api.github.com/repos/rminnich/u-root/subscribers","subscription_url":"https://api.github.com/repos/rminnich/u-root/subscription","commits_url":"https://api.github.com/repos/rminnich/u-root/commits{/sha}","git_commits_url":"https://api.github.com/repos/rminnich/u-root/git/commits{/sha}","comments_url":"https://api.github.com/repos/rminnich/u-root/comments{/number}","issue_comment_url":"https://api.github.com/repos/rminnich/u-root/issues/comments{/number}","contents_url":"https://api.github.com/repos/rminnich/u-root/contents/{+path}","compare_url":"https://api.github.com/repos/rminnich/u-root/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rminnich/u-root/merges","archive_url":"https://api.github.com/repos/rminnich/u-root/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rminnich/u-root/downloads","issues_url":"https://api.github.com/repos/rminnich/u-root/issues{/number}","pulls_url":"https://api.github.com/repos/rminnich/u-root/pulls{/number}","milestones_url":"https://api.github.com/repos/rminnich/u-root/milestones{/number}","notifications_url":"https://api.github.com/repos/rminnich/u-root/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rminnich/u-root/labels{/name}","releases_url":"https://api.github.com/repos/rminnich/u-root/releases{/id}","created_at":"2012-10-29T17:16:24Z","updated_at":"2015-08-27T17:53:26Z","pushed_at":"2015-08-28T22:15:57Z","git_url":"git://github.com/rminnich/u-root.git","ssh_url":"git@github.com:rminnich/u-root.git","clone_url":"https://github.com/rminnich/u-root.git","svn_url":"https://github.com/rminnich/u-root","homepage":null,"size":11152,"stargazers_count":42,"watchers_count":42,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":6,"forks":7,"open_issues":6,"watchers":42,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rminnich/u-root/pulls/15"},"html":{"href":"https://github.com/rminnich/u-root/pull/15"},"issue":{"href":"https://api.github.com/repos/rminnich/u-root/issues/15"},"comments":{"href":"https://api.github.com/repos/rminnich/u-root/issues/15/comments"},"review_comments":{"href":"https://api.github.com/repos/rminnich/u-root/pulls/15/comments"},"review_comment":{"href":"https://api.github.com/repos/rminnich/u-root/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rminnich/u-root/pulls/15/commits"},"statuses":{"href":"https://api.github.com/repos/rminnich/u-root/statuses/b05ec3382f78dd4bba398ecc8dcd80308805bcc2"}}}}