{"action":"created","comment":{"url":"https://api.github.com/repos/D-Programming-Language/tools/pulls/comments/23792609","id":23792609,"diff_hunk":"@@ -0,0 +1,184 @@\n+module scriptutil;\n+import core.sys.posix.unistd:geteuid;\n+static import std.ascii;\n+import std.typecons:Tuple,tuple;\n+import std.datetime:Clock,SysTime;\n+import std.digest.digest:digest;\n+import std.digest.crc:crcHexString,CRC32;\n+import std.file:mkdir,exists,isDir,File,dirSeparator;\n+import std.process:executeShell;\n+import std.string:strip,indexOf,munch;\n+import std.array:join;\n+import std.math:pow;\n+import std.algorithm:max;\n+import std.random:uniform;\n+import std.conv:to;\n+import std.stdio:writefln,stdout;\n+// shamelessly nicked from http://www.mktemp.org/repos/mktemp/file/e4089ef40fd0/mkdtemp.c\n+\n+\n+private string makeHash(immutable string path)\n+{\n+\treturn digest!CRC32(path).crcHexString ~ digest!CRC32((Clock.currTime.toISOExtString)).crcHexString;\n+}\n+\n+private enum permittedCharacters= std.ascii.letters ~ std.ascii.digits;\n+\n+private string makeRandomAlphaNumeric(size_t numChars)\n+{\n+\tstring ret=\"\";\n+\tforeach(i;0..numChars)\n+\t{\n+\t\tauto r=uniform(0,permittedCharacters.length);\n+\t\tret~=to!char(r);\n+\t}\n+\treturn ret;\n+}\n+\n+\n+enum TempDirMode\n+{\n+\tcreateFile,\n+\tcreateDirectory,\n+}\n+\n+enum MaxTries=100_000;\n+\n+string makeTempEntry(string path, TempDirMode mode)\n+{\n+\tif (path.length==0)\n+\t\tthrow new Exception(\"mkdTempInternal: trying to create directory in empty path\");\n+\n+\tauto firstindex=path.indexOf(\"X\"); // just add the temp junk to the end if no X specified\n+\tsize_t lastindex=-1;\n+\tstring frontStub,backStub;\n+\tauto numVarChars=((lastindex-firstindex)>2)?(lastindex-firstindex):2;\n+\n+\tif (firstindex!=-1)\n+\t\tlastindex=path[firstindex..$].indexOf(\"X\")+firstindex;\n+\tfrontStub=(firstindex!=-1)?path[0..firstindex]:\"\";\n+\tbackStub=(lastindex!=-1)?path[lastindex..$]:\"\";\n+\tFile f;\n+\n+\tforeach(trycount;0..max(MaxTries,pow(permittedCharacters.length,numVarChars)/5))\n+\t{\n+\t\tauto tempPath=frontStub~((numVarChars>8)?makeHash(path):\"\")~makeRandomAlphaNumeric(lastindex-firstindex);\n+\t\tdebug\n+\t\t{\n+\t\t\twritefln(\"%s trying to make temp entry in %s\",tempPath);\n+\t\t\tstdout.flush();\n+\t\t}\n+\t\tif (exists(tempPath))\n+\t\t\tcontinue;\n+\n+\t\tif (mode==TempDirMode.createFile)\n+\t\t{\n+\t\t\tthrow new Exception(\"safe create file not yet supported\");\n+\t\t\t/*if safeCreateFile(tempPath)\n+\t\t\t\treturn tempPath;*/\n+\t\t}\n+\t\telse\n+\t\t{\n+\t\t\tif (safeCreateDir(tempPath))\n+\t\t\t\treturn tempPath;\n+\t\t}\n+\t}\n+\t\n+\tthrow new Exception (\"makeTempEntry unable to  \"~ to!string(mode) ~\"  in generic path \" ~ path );\n+\tassert(0);","path":"updatesh_d/scriptutil.d","position":88,"original_position":88,"commit_id":"4abc8acc71c50effe0db1912c0bf454146352f78","original_commit_id":"4abc8acc71c50effe0db1912c0bf454146352f78","user":{"login":"andralex","id":566679,"avatar_url":"https://avatars.githubusercontent.com/u/566679?v=3","gravatar_id":"","url":"https://api.github.com/users/andralex","html_url":"https://github.com/andralex","followers_url":"https://api.github.com/users/andralex/followers","following_url":"https://api.github.com/users/andralex/following{/other_user}","gists_url":"https://api.github.com/users/andralex/gists{/gist_id}","starred_url":"https://api.github.com/users/andralex/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andralex/subscriptions","organizations_url":"https://api.github.com/users/andralex/orgs","repos_url":"https://api.github.com/users/andralex/repos","events_url":"https://api.github.com/users/andralex/events{/privacy}","received_events_url":"https://api.github.com/users/andralex/received_events","type":"User","site_admin":false},"body":"remove","created_at":"2015-01-29T18:57:51Z","updated_at":"2015-01-29T18:57:51Z","html_url":"https://github.com/D-Programming-Language/tools/pull/158#discussion_r23792609","pull_request_url":"https://api.github.com/repos/D-Programming-Language/tools/pulls/158","_links":{"self":{"href":"https://api.github.com/repos/D-Programming-Language/tools/pulls/comments/23792609"},"html":{"href":"https://github.com/D-Programming-Language/tools/pull/158#discussion_r23792609"},"pull_request":{"href":"https://api.github.com/repos/D-Programming-Language/tools/pulls/158"}}},"pull_request":{"url":"https://api.github.com/repos/D-Programming-Language/tools/pulls/158","id":28259970,"html_url":"https://github.com/D-Programming-Language/tools/pull/158","diff_url":"https://github.com/D-Programming-Language/tools/pull/158.diff","patch_url":"https://github.com/D-Programming-Language/tools/pull/158.patch","issue_url":"https://api.github.com/repos/D-Programming-Language/tools/issues/158","number":158,"state":"open","locked":false,"title":"Ported update.sh to D which will make it easier to run on Windows/OS X also","user":{"login":"Laeeth","id":6643582,"avatar_url":"https://avatars.githubusercontent.com/u/6643582?v=3","gravatar_id":"","url":"https://api.github.com/users/Laeeth","html_url":"https://github.com/Laeeth","followers_url":"https://api.github.com/users/Laeeth/followers","following_url":"https://api.github.com/users/Laeeth/following{/other_user}","gists_url":"https://api.github.com/users/Laeeth/gists{/gist_id}","starred_url":"https://api.github.com/users/Laeeth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Laeeth/subscriptions","organizations_url":"https://api.github.com/users/Laeeth/orgs","repos_url":"https://api.github.com/users/Laeeth/repos","events_url":"https://api.github.com/users/Laeeth/events{/privacy}","received_events_url":"https://api.github.com/users/Laeeth/received_events","type":"User","site_admin":false},"body":"Hi.\r\n\r\nPorted update.sh to D - hope this might be of some use.  I don't pretend it is pretty generally, and in particular I tried to stick to the structure of the original script for clarity, even though it would be more elegant to factor out the repetition.\r\n\r\nJust run makeit.sh to compile - you may want to change the compiler to dmd.  I destroyed my system dmd with a null file when working on it, so changed to ldc temporarily.\r\n\r\n\r\nLaeeth.","created_at":"2015-01-29T08:02:47Z","updated_at":"2015-01-29T18:57:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ac189def6378281873202e51f65d5f4ea43f2b8c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/D-Programming-Language/tools/pulls/158/commits","review_comments_url":"https://api.github.com/repos/D-Programming-Language/tools/pulls/158/comments","review_comment_url":"https://api.github.com/repos/D-Programming-Language/tools/pulls/comments/{number}","comments_url":"https://api.github.com/repos/D-Programming-Language/tools/issues/158/comments","statuses_url":"https://api.github.com/repos/D-Programming-Language/tools/statuses/4abc8acc71c50effe0db1912c0bf454146352f78","head":{"label":"Laeeth:master","ref":"master","sha":"4abc8acc71c50effe0db1912c0bf454146352f78","user":{"login":"Laeeth","id":6643582,"avatar_url":"https://avatars.githubusercontent.com/u/6643582?v=3","gravatar_id":"","url":"https://api.github.com/users/Laeeth","html_url":"https://github.com/Laeeth","followers_url":"https://api.github.com/users/Laeeth/followers","following_url":"https://api.github.com/users/Laeeth/following{/other_user}","gists_url":"https://api.github.com/users/Laeeth/gists{/gist_id}","starred_url":"https://api.github.com/users/Laeeth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Laeeth/subscriptions","organizations_url":"https://api.github.com/users/Laeeth/orgs","repos_url":"https://api.github.com/users/Laeeth/repos","events_url":"https://api.github.com/users/Laeeth/events{/privacy}","received_events_url":"https://api.github.com/users/Laeeth/received_events","type":"User","site_admin":false},"repo":{"id":30009690,"name":"tools","full_name":"Laeeth/tools","owner":{"login":"Laeeth","id":6643582,"avatar_url":"https://avatars.githubusercontent.com/u/6643582?v=3","gravatar_id":"","url":"https://api.github.com/users/Laeeth","html_url":"https://github.com/Laeeth","followers_url":"https://api.github.com/users/Laeeth/followers","following_url":"https://api.github.com/users/Laeeth/following{/other_user}","gists_url":"https://api.github.com/users/Laeeth/gists{/gist_id}","starred_url":"https://api.github.com/users/Laeeth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Laeeth/subscriptions","organizations_url":"https://api.github.com/users/Laeeth/orgs","repos_url":"https://api.github.com/users/Laeeth/repos","events_url":"https://api.github.com/users/Laeeth/events{/privacy}","received_events_url":"https://api.github.com/users/Laeeth/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Laeeth/tools","description":"Ancillary tools for the D programming language compiler","fork":true,"url":"https://api.github.com/repos/Laeeth/tools","forks_url":"https://api.github.com/repos/Laeeth/tools/forks","keys_url":"https://api.github.com/repos/Laeeth/tools/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Laeeth/tools/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Laeeth/tools/teams","hooks_url":"https://api.github.com/repos/Laeeth/tools/hooks","issue_events_url":"https://api.github.com/repos/Laeeth/tools/issues/events{/number}","events_url":"https://api.github.com/repos/Laeeth/tools/events","assignees_url":"https://api.github.com/repos/Laeeth/tools/assignees{/user}","branches_url":"https://api.github.com/repos/Laeeth/tools/branches{/branch}","tags_url":"https://api.github.com/repos/Laeeth/tools/tags","blobs_url":"https://api.github.com/repos/Laeeth/tools/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Laeeth/tools/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Laeeth/tools/git/refs{/sha}","trees_url":"https://api.github.com/repos/Laeeth/tools/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Laeeth/tools/statuses/{sha}","languages_url":"https://api.github.com/repos/Laeeth/tools/languages","stargazers_url":"https://api.github.com/repos/Laeeth/tools/stargazers","contributors_url":"https://api.github.com/repos/Laeeth/tools/contributors","subscribers_url":"https://api.github.com/repos/Laeeth/tools/subscribers","subscription_url":"https://api.github.com/repos/Laeeth/tools/subscription","commits_url":"https://api.github.com/repos/Laeeth/tools/commits{/sha}","git_commits_url":"https://api.github.com/repos/Laeeth/tools/git/commits{/sha}","comments_url":"https://api.github.com/repos/Laeeth/tools/comments{/number}","issue_comment_url":"https://api.github.com/repos/Laeeth/tools/issues/comments/{number}","contents_url":"https://api.github.com/repos/Laeeth/tools/contents/{+path}","compare_url":"https://api.github.com/repos/Laeeth/tools/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Laeeth/tools/merges","archive_url":"https://api.github.com/repos/Laeeth/tools/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Laeeth/tools/downloads","issues_url":"https://api.github.com/repos/Laeeth/tools/issues{/number}","pulls_url":"https://api.github.com/repos/Laeeth/tools/pulls{/number}","milestones_url":"https://api.github.com/repos/Laeeth/tools/milestones{/number}","notifications_url":"https://api.github.com/repos/Laeeth/tools/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Laeeth/tools/labels{/name}","releases_url":"https://api.github.com/repos/Laeeth/tools/releases{/id}","created_at":"2015-01-29T07:53:21Z","updated_at":"2015-01-29T08:00:00Z","pushed_at":"2015-01-29T08:00:00Z","git_url":"git://github.com/Laeeth/tools.git","ssh_url":"git@github.com:Laeeth/tools.git","clone_url":"https://github.com/Laeeth/tools.git","svn_url":"https://github.com/Laeeth/tools","homepage":"http://dlang.org","size":1096,"stargazers_count":0,"watchers_count":0,"language":"D","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"D-Programming-Language:master","ref":"master","sha":"b4c3322153e569f2245eaf7ddc5ea01b9b30c943","user":{"login":"D-Programming-Language","id":565913,"avatar_url":"https://avatars.githubusercontent.com/u/565913?v=3","gravatar_id":"","url":"https://api.github.com/users/D-Programming-Language","html_url":"https://github.com/D-Programming-Language","followers_url":"https://api.github.com/users/D-Programming-Language/followers","following_url":"https://api.github.com/users/D-Programming-Language/following{/other_user}","gists_url":"https://api.github.com/users/D-Programming-Language/gists{/gist_id}","starred_url":"https://api.github.com/users/D-Programming-Language/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/D-Programming-Language/subscriptions","organizations_url":"https://api.github.com/users/D-Programming-Language/orgs","repos_url":"https://api.github.com/users/D-Programming-Language/repos","events_url":"https://api.github.com/users/D-Programming-Language/events{/privacy}","received_events_url":"https://api.github.com/users/D-Programming-Language/received_events","type":"Organization","site_admin":false},"repo":{"id":1262864,"name":"tools","full_name":"D-Programming-Language/tools","owner":{"login":"D-Programming-Language","id":565913,"avatar_url":"https://avatars.githubusercontent.com/u/565913?v=3","gravatar_id":"","url":"https://api.github.com/users/D-Programming-Language","html_url":"https://github.com/D-Programming-Language","followers_url":"https://api.github.com/users/D-Programming-Language/followers","following_url":"https://api.github.com/users/D-Programming-Language/following{/other_user}","gists_url":"https://api.github.com/users/D-Programming-Language/gists{/gist_id}","starred_url":"https://api.github.com/users/D-Programming-Language/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/D-Programming-Language/subscriptions","organizations_url":"https://api.github.com/users/D-Programming-Language/orgs","repos_url":"https://api.github.com/users/D-Programming-Language/repos","events_url":"https://api.github.com/users/D-Programming-Language/events{/privacy}","received_events_url":"https://api.github.com/users/D-Programming-Language/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/D-Programming-Language/tools","description":"Ancillary tools for the D programming language compiler","fork":false,"url":"https://api.github.com/repos/D-Programming-Language/tools","forks_url":"https://api.github.com/repos/D-Programming-Language/tools/forks","keys_url":"https://api.github.com/repos/D-Programming-Language/tools/keys{/key_id}","collaborators_url":"https://api.github.com/repos/D-Programming-Language/tools/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/D-Programming-Language/tools/teams","hooks_url":"https://api.github.com/repos/D-Programming-Language/tools/hooks","issue_events_url":"https://api.github.com/repos/D-Programming-Language/tools/issues/events{/number}","events_url":"https://api.github.com/repos/D-Programming-Language/tools/events","assignees_url":"https://api.github.com/repos/D-Programming-Language/tools/assignees{/user}","branches_url":"https://api.github.com/repos/D-Programming-Language/tools/branches{/branch}","tags_url":"https://api.github.com/repos/D-Programming-Language/tools/tags","blobs_url":"https://api.github.com/repos/D-Programming-Language/tools/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/D-Programming-Language/tools/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/D-Programming-Language/tools/git/refs{/sha}","trees_url":"https://api.github.com/repos/D-Programming-Language/tools/git/trees{/sha}","statuses_url":"https://api.github.com/repos/D-Programming-Language/tools/statuses/{sha}","languages_url":"https://api.github.com/repos/D-Programming-Language/tools/languages","stargazers_url":"https://api.github.com/repos/D-Programming-Language/tools/stargazers","contributors_url":"https://api.github.com/repos/D-Programming-Language/tools/contributors","subscribers_url":"https://api.github.com/repos/D-Programming-Language/tools/subscribers","subscription_url":"https://api.github.com/repos/D-Programming-Language/tools/subscription","commits_url":"https://api.github.com/repos/D-Programming-Language/tools/commits{/sha}","git_commits_url":"https://api.github.com/repos/D-Programming-Language/tools/git/commits{/sha}","comments_url":"https://api.github.com/repos/D-Programming-Language/tools/comments{/number}","issue_comment_url":"https://api.github.com/repos/D-Programming-Language/tools/issues/comments/{number}","contents_url":"https://api.github.com/repos/D-Programming-Language/tools/contents/{+path}","compare_url":"https://api.github.com/repos/D-Programming-Language/tools/compare/{base}...{head}","merges_url":"https://api.github.com/repos/D-Programming-Language/tools/merges","archive_url":"https://api.github.com/repos/D-Programming-Language/tools/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/D-Programming-Language/tools/downloads","issues_url":"https://api.github.com/repos/D-Programming-Language/tools/issues{/number}","pulls_url":"https://api.github.com/repos/D-Programming-Language/tools/pulls{/number}","milestones_url":"https://api.github.com/repos/D-Programming-Language/tools/milestones{/number}","notifications_url":"https://api.github.com/repos/D-Programming-Language/tools/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/D-Programming-Language/tools/labels{/name}","releases_url":"https://api.github.com/repos/D-Programming-Language/tools/releases{/id}","created_at":"2011-01-17T09:07:05Z","updated_at":"2015-01-28T21:52:06Z","pushed_at":"2015-01-28T21:52:06Z","git_url":"git://github.com/D-Programming-Language/tools.git","ssh_url":"git@github.com:D-Programming-Language/tools.git","clone_url":"https://github.com/D-Programming-Language/tools.git","svn_url":"https://github.com/D-Programming-Language/tools","homepage":"http://dlang.org","size":1096,"stargazers_count":91,"watchers_count":91,"language":"D","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":80,"mirror_url":null,"open_issues_count":3,"forks":80,"open_issues":3,"watchers":91,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/D-Programming-Language/tools/pulls/158"},"html":{"href":"https://github.com/D-Programming-Language/tools/pull/158"},"issue":{"href":"https://api.github.com/repos/D-Programming-Language/tools/issues/158"},"comments":{"href":"https://api.github.com/repos/D-Programming-Language/tools/issues/158/comments"},"review_comments":{"href":"https://api.github.com/repos/D-Programming-Language/tools/pulls/158/comments"},"review_comment":{"href":"https://api.github.com/repos/D-Programming-Language/tools/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/D-Programming-Language/tools/pulls/158/commits"},"statuses":{"href":"https://api.github.com/repos/D-Programming-Language/tools/statuses/4abc8acc71c50effe0db1912c0bf454146352f78"}}}}