{"action":"created","comment":{"url":"https://api.github.com/repos/npm/npm/pulls/comments/71246805","id":71246805,"diff_hunk":"@@ -75,18 +76,38 @@ function lifecycle (pkg, stage, wd, unsafe, failOk, cb) {\n     env.npm_node_execpath = env.NODE = env.NODE || process.execPath\n     env.npm_execpath = require.main.filename\n \n-    // 'nobody' typically doesn't have permission to write to /tmp\n-    // even if it's never used, sh freaks out.\n-    if (!npm.config.get('unsafe-perm')) env.TMPDIR = wd\n+    _getTemporaryDirectory(wd, process.env, function (er, tmpdir) {\n+      if (er) return cb(er)\n \n-    lifecycle_(pkg, stage, wd, env, unsafe, failOk, cb)\n+      env.TMPDIR = tmpdir\n+      lifecycle_(pkg, stage, wd, env, unsafe, failOk, cb)\n+    })\n   })\n }\n \n function _incorrectWorkingDirectory (wd, pkg) {\n   return wd.lastIndexOf(pkg.name) !== wd.length - pkg.name.length\n }\n \n+function _getTemporaryDirectory (wd, env, cb) {\n+  if (_isWritable(env.TMPDIR)) return cb(null, env.TMPDIR)\n+\n+  // 'nobody' typically doesn't have permission to write to /tmp\n+  // even if it's never used, sh freaks out.\n+  if (_isWritable(wd)) return cb(null, wd)\n+\n+  cb(new Error('Cannot find writable TMPDIR, please set TMPDIR to something writable'))\n+}\n+\n+function _isWritable (dir) {\n+  try {\n+    fs.accessSync(dir, fs.W_OK)\n+    return true\n+  } catch (e) {\n+    return false\n+  }","path":"lib/utils/lifecycle.js","position":45,"original_position":45,"commit_id":"de83f16ed37811386f66a72bb0703ced755c0c94","original_commit_id":"de83f16ed37811386f66a72bb0703ced755c0c94","user":{"login":"aaronjensen","id":8588,"avatar_url":"https://avatars.githubusercontent.com/u/8588?v=3","gravatar_id":"","url":"https://api.github.com/users/aaronjensen","html_url":"https://github.com/aaronjensen","followers_url":"https://api.github.com/users/aaronjensen/followers","following_url":"https://api.github.com/users/aaronjensen/following{/other_user}","gists_url":"https://api.github.com/users/aaronjensen/gists{/gist_id}","starred_url":"https://api.github.com/users/aaronjensen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aaronjensen/subscriptions","organizations_url":"https://api.github.com/users/aaronjensen/orgs","repos_url":"https://api.github.com/users/aaronjensen/repos","events_url":"https://api.github.com/users/aaronjensen/events{/privacy}","received_events_url":"https://api.github.com/users/aaronjensen/received_events","type":"User","site_admin":false},"body":"I'm not a fan of using exceptions in this way, but it felt like an awkward place to have to use callbacks. If you'd prefer that let me know and I can switch it out.","created_at":"2016-07-18T23:01:20Z","updated_at":"2016-07-18T23:01:20Z","html_url":"https://github.com/npm/npm/pull/13344#discussion_r71246805","pull_request_url":"https://api.github.com/repos/npm/npm/pulls/13344","_links":{"self":{"href":"https://api.github.com/repos/npm/npm/pulls/comments/71246805"},"html":{"href":"https://github.com/npm/npm/pull/13344#discussion_r71246805"},"pull_request":{"href":"https://api.github.com/repos/npm/npm/pulls/13344"}}},"pull_request":{"url":"https://api.github.com/repos/npm/npm/pulls/13344","id":77054197,"html_url":"https://github.com/npm/npm/pull/13344","diff_url":"https://github.com/npm/npm/pull/13344.diff","patch_url":"https://github.com/npm/npm/pull/13344.patch","issue_url":"https://api.github.com/repos/npm/npm/issues/13344","number":13344,"state":"open","locked":false,"title":"Do not overwrite TMPDIR","user":{"login":"aaronjensen","id":8588,"avatar_url":"https://avatars.githubusercontent.com/u/8588?v=3","gravatar_id":"","url":"https://api.github.com/users/aaronjensen","html_url":"https://github.com/aaronjensen","followers_url":"https://api.github.com/users/aaronjensen/followers","following_url":"https://api.github.com/users/aaronjensen/following{/other_user}","gists_url":"https://api.github.com/users/aaronjensen/gists{/gist_id}","starred_url":"https://api.github.com/users/aaronjensen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aaronjensen/subscriptions","organizations_url":"https://api.github.com/users/aaronjensen/orgs","repos_url":"https://api.github.com/users/aaronjensen/repos","events_url":"https://api.github.com/users/aaronjensen/events{/privacy}","received_events_url":"https://api.github.com/users/aaronjensen/received_events","type":"User","site_admin":false},"body":"Fixes #13325 \r\n\r\nMaybe a check for 'nobody' would be more appropriate, I don't know, but this existing behavior is surprising and causes mysterious/confusing problems. ","created_at":"2016-07-12T02:53:17Z","updated_at":"2016-07-18T23:01:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8f46b1ddc3a32aca58dc30e491fa80fcf6734807","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/npm/npm/pulls/13344/commits","review_comments_url":"https://api.github.com/repos/npm/npm/pulls/13344/comments","review_comment_url":"https://api.github.com/repos/npm/npm/pulls/comments{/number}","comments_url":"https://api.github.com/repos/npm/npm/issues/13344/comments","statuses_url":"https://api.github.com/repos/npm/npm/statuses/de83f16ed37811386f66a72bb0703ced755c0c94","head":{"label":"aaronjensen:patch-1","ref":"patch-1","sha":"de83f16ed37811386f66a72bb0703ced755c0c94","user":{"login":"aaronjensen","id":8588,"avatar_url":"https://avatars.githubusercontent.com/u/8588?v=3","gravatar_id":"","url":"https://api.github.com/users/aaronjensen","html_url":"https://github.com/aaronjensen","followers_url":"https://api.github.com/users/aaronjensen/followers","following_url":"https://api.github.com/users/aaronjensen/following{/other_user}","gists_url":"https://api.github.com/users/aaronjensen/gists{/gist_id}","starred_url":"https://api.github.com/users/aaronjensen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aaronjensen/subscriptions","organizations_url":"https://api.github.com/users/aaronjensen/orgs","repos_url":"https://api.github.com/users/aaronjensen/repos","events_url":"https://api.github.com/users/aaronjensen/events{/privacy}","received_events_url":"https://api.github.com/users/aaronjensen/received_events","type":"User","site_admin":false},"repo":{"id":63121087,"name":"npm","full_name":"aaronjensen/npm","owner":{"login":"aaronjensen","id":8588,"avatar_url":"https://avatars.githubusercontent.com/u/8588?v=3","gravatar_id":"","url":"https://api.github.com/users/aaronjensen","html_url":"https://github.com/aaronjensen","followers_url":"https://api.github.com/users/aaronjensen/followers","following_url":"https://api.github.com/users/aaronjensen/following{/other_user}","gists_url":"https://api.github.com/users/aaronjensen/gists{/gist_id}","starred_url":"https://api.github.com/users/aaronjensen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aaronjensen/subscriptions","organizations_url":"https://api.github.com/users/aaronjensen/orgs","repos_url":"https://api.github.com/users/aaronjensen/repos","events_url":"https://api.github.com/users/aaronjensen/events{/privacy}","received_events_url":"https://api.github.com/users/aaronjensen/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/aaronjensen/npm","description":"a package manager for javascript","fork":true,"url":"https://api.github.com/repos/aaronjensen/npm","forks_url":"https://api.github.com/repos/aaronjensen/npm/forks","keys_url":"https://api.github.com/repos/aaronjensen/npm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aaronjensen/npm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aaronjensen/npm/teams","hooks_url":"https://api.github.com/repos/aaronjensen/npm/hooks","issue_events_url":"https://api.github.com/repos/aaronjensen/npm/issues/events{/number}","events_url":"https://api.github.com/repos/aaronjensen/npm/events","assignees_url":"https://api.github.com/repos/aaronjensen/npm/assignees{/user}","branches_url":"https://api.github.com/repos/aaronjensen/npm/branches{/branch}","tags_url":"https://api.github.com/repos/aaronjensen/npm/tags","blobs_url":"https://api.github.com/repos/aaronjensen/npm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aaronjensen/npm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aaronjensen/npm/git/refs{/sha}","trees_url":"https://api.github.com/repos/aaronjensen/npm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aaronjensen/npm/statuses/{sha}","languages_url":"https://api.github.com/repos/aaronjensen/npm/languages","stargazers_url":"https://api.github.com/repos/aaronjensen/npm/stargazers","contributors_url":"https://api.github.com/repos/aaronjensen/npm/contributors","subscribers_url":"https://api.github.com/repos/aaronjensen/npm/subscribers","subscription_url":"https://api.github.com/repos/aaronjensen/npm/subscription","commits_url":"https://api.github.com/repos/aaronjensen/npm/commits{/sha}","git_commits_url":"https://api.github.com/repos/aaronjensen/npm/git/commits{/sha}","comments_url":"https://api.github.com/repos/aaronjensen/npm/comments{/number}","issue_comment_url":"https://api.github.com/repos/aaronjensen/npm/issues/comments{/number}","contents_url":"https://api.github.com/repos/aaronjensen/npm/contents/{+path}","compare_url":"https://api.github.com/repos/aaronjensen/npm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aaronjensen/npm/merges","archive_url":"https://api.github.com/repos/aaronjensen/npm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aaronjensen/npm/downloads","issues_url":"https://api.github.com/repos/aaronjensen/npm/issues{/number}","pulls_url":"https://api.github.com/repos/aaronjensen/npm/pulls{/number}","milestones_url":"https://api.github.com/repos/aaronjensen/npm/milestones{/number}","notifications_url":"https://api.github.com/repos/aaronjensen/npm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aaronjensen/npm/labels{/name}","releases_url":"https://api.github.com/repos/aaronjensen/npm/releases{/id}","deployments_url":"https://api.github.com/repos/aaronjensen/npm/deployments","created_at":"2016-07-12T02:51:26Z","updated_at":"2016-07-12T02:51:36Z","pushed_at":"2016-07-18T22:58:51Z","git_url":"git://github.com/aaronjensen/npm.git","ssh_url":"git@github.com:aaronjensen/npm.git","clone_url":"https://github.com/aaronjensen/npm.git","svn_url":"https://github.com/aaronjensen/npm","homepage":"http://www.npmjs.com/","size":31474,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","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":"npm:master","ref":"master","sha":"6da8d1d47eb3f933fffd47952079dd3d94e9fe25","user":{"login":"npm","id":6078720,"avatar_url":"https://avatars.githubusercontent.com/u/6078720?v=3","gravatar_id":"","url":"https://api.github.com/users/npm","html_url":"https://github.com/npm","followers_url":"https://api.github.com/users/npm/followers","following_url":"https://api.github.com/users/npm/following{/other_user}","gists_url":"https://api.github.com/users/npm/gists{/gist_id}","starred_url":"https://api.github.com/users/npm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/npm/subscriptions","organizations_url":"https://api.github.com/users/npm/orgs","repos_url":"https://api.github.com/users/npm/repos","events_url":"https://api.github.com/users/npm/events{/privacy}","received_events_url":"https://api.github.com/users/npm/received_events","type":"Organization","site_admin":false},"repo":{"id":321278,"name":"npm","full_name":"npm/npm","owner":{"login":"npm","id":6078720,"avatar_url":"https://avatars.githubusercontent.com/u/6078720?v=3","gravatar_id":"","url":"https://api.github.com/users/npm","html_url":"https://github.com/npm","followers_url":"https://api.github.com/users/npm/followers","following_url":"https://api.github.com/users/npm/following{/other_user}","gists_url":"https://api.github.com/users/npm/gists{/gist_id}","starred_url":"https://api.github.com/users/npm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/npm/subscriptions","organizations_url":"https://api.github.com/users/npm/orgs","repos_url":"https://api.github.com/users/npm/repos","events_url":"https://api.github.com/users/npm/events{/privacy}","received_events_url":"https://api.github.com/users/npm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/npm/npm","description":"a package manager for javascript","fork":false,"url":"https://api.github.com/repos/npm/npm","forks_url":"https://api.github.com/repos/npm/npm/forks","keys_url":"https://api.github.com/repos/npm/npm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/npm/npm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/npm/npm/teams","hooks_url":"https://api.github.com/repos/npm/npm/hooks","issue_events_url":"https://api.github.com/repos/npm/npm/issues/events{/number}","events_url":"https://api.github.com/repos/npm/npm/events","assignees_url":"https://api.github.com/repos/npm/npm/assignees{/user}","branches_url":"https://api.github.com/repos/npm/npm/branches{/branch}","tags_url":"https://api.github.com/repos/npm/npm/tags","blobs_url":"https://api.github.com/repos/npm/npm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/npm/npm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/npm/npm/git/refs{/sha}","trees_url":"https://api.github.com/repos/npm/npm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/npm/npm/statuses/{sha}","languages_url":"https://api.github.com/repos/npm/npm/languages","stargazers_url":"https://api.github.com/repos/npm/npm/stargazers","contributors_url":"https://api.github.com/repos/npm/npm/contributors","subscribers_url":"https://api.github.com/repos/npm/npm/subscribers","subscription_url":"https://api.github.com/repos/npm/npm/subscription","commits_url":"https://api.github.com/repos/npm/npm/commits{/sha}","git_commits_url":"https://api.github.com/repos/npm/npm/git/commits{/sha}","comments_url":"https://api.github.com/repos/npm/npm/comments{/number}","issue_comment_url":"https://api.github.com/repos/npm/npm/issues/comments{/number}","contents_url":"https://api.github.com/repos/npm/npm/contents/{+path}","compare_url":"https://api.github.com/repos/npm/npm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/npm/npm/merges","archive_url":"https://api.github.com/repos/npm/npm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/npm/npm/downloads","issues_url":"https://api.github.com/repos/npm/npm/issues{/number}","pulls_url":"https://api.github.com/repos/npm/npm/pulls{/number}","milestones_url":"https://api.github.com/repos/npm/npm/milestones{/number}","notifications_url":"https://api.github.com/repos/npm/npm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/npm/npm/labels{/name}","releases_url":"https://api.github.com/repos/npm/npm/releases{/id}","deployments_url":"https://api.github.com/repos/npm/npm/deployments","created_at":"2009-09-29T17:21:24Z","updated_at":"2016-07-18T17:52:18Z","pushed_at":"2016-07-18T22:58:52Z","git_url":"git://github.com/npm/npm.git","ssh_url":"git@github.com:npm/npm.git","clone_url":"https://github.com/npm/npm.git","svn_url":"https://github.com/npm/npm","homepage":"http://www.npmjs.com/","size":50184,"stargazers_count":9812,"watchers_count":9812,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2031,"mirror_url":null,"open_issues_count":2428,"forks":2031,"open_issues":2428,"watchers":9812,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/npm/npm/pulls/13344"},"html":{"href":"https://github.com/npm/npm/pull/13344"},"issue":{"href":"https://api.github.com/repos/npm/npm/issues/13344"},"comments":{"href":"https://api.github.com/repos/npm/npm/issues/13344/comments"},"review_comments":{"href":"https://api.github.com/repos/npm/npm/pulls/13344/comments"},"review_comment":{"href":"https://api.github.com/repos/npm/npm/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/npm/npm/pulls/13344/commits"},"statuses":{"href":"https://api.github.com/repos/npm/npm/statuses/de83f16ed37811386f66a72bb0703ced755c0c94"}}}}
{"actor":{"display_login":"aaronjensen"}}