Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.2k
os: add userInfo() method#6104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Conversation
addaleax commented Apr 7, 2016
Might it be a good idea to name this differently?
|
mscdex commented Apr 7, 2016
I agree that it should probably be named something else. I don't have any suggestions at the moment though. I suppose |
bnoordhuis commented Apr 7, 2016
Alternatively, you could expose the individual properties as functions. If you stick with the object-with-properties approach, then the documentation should explain the difference between |
Fishrock123 commented Apr 7, 2016
+1 to renaming, or separating out |
jasnell commented Apr 7, 2016
+1 to renaming. The change LGTM with that change made. |
78722ca to 4abd014Comparecjihrig commented Apr 8, 2016
Updated. I decided to rename to |
src/node_os.cc Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick nit: given the likelihood that this is running on linux, there's a possibility that this may not actually be a OneByteString. It complicates things just a bit, but it might be worthwhile allowing an optional options (e.g. {encoding:'utf8'} to be passed in to GetUserInfo so that the encoding of the path can be specified. This would make it consistent with the new Buffer support in the fs module.
jasnell commented Apr 8, 2016
LGTM. Left a comment that could be deferred to a separate PR if necessary. |
doc/api/os.markdown Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shell and homedir should be swapped here because that's the way they appear in passwd.
silverwind commented Apr 8, 2016
I'm also worried about the duplication and the fact that it's not Windows compatible. Are there use cases where |
Fishrock123 commented Apr 8, 2016
What about |
jasnell commented Apr 8, 2016
@silverwind ... as I understand it, yes. I cannot recall the exact issue number but there is an open request to be able to retrieve the actual user information separately from the environment variables in certain use cases. The reason is that the env var could actually be incorrect in those edge cases. The fact that this is not Windows compatible is not too concerning to me. We already have plenty of similar cases. |
jasnell commented Apr 8, 2016
I'd prefer keeping it to just |
silverwind commented Apr 8, 2016
How about adding |
sindresorhus commented Apr 9, 2016
👍 On OS X at least it contains the user's fullname, which I could use for my |
cjihrig commented Apr 10, 2016
@jasnell I changed to UTF8 for consistency with |
cjihrig commented Apr 10, 2016
re: |
jasnell commented Apr 10, 2016
In that edge case, the dev could pass encoding: 'buffer' and get back
|
jasnell commented Apr 12, 2016
Refs: #5582 |
cjihrig commented Apr 12, 2016
@jasnell updated to include an encoding option. |
doc/api/os.markdown Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: perhaps add a short note that if encoding is passed as 'buffer' the username, homedir, and shell will be returned as Buffer instances.
jasnell commented Apr 12, 2016
LGTM with a nit. |
cjihrig commented Apr 12, 2016
nit addressed. CI is green: https://ci.nodejs.org/job/node-test-pull-request/2248/ |
os.userInfo() calls libuv's uv_os_get_passwd() function. It returns an object containing the current effective user's username, uid, gid, shell, and home directory. On Windows, the uid and gid are -1, and the shell is null. Refs: nodejs#5582 PR-URL: nodejs#6104 Reviewed-By: James M Snell <[email protected]>
sindresorhus commented Apr 14, 2016
I made a polyfill for anyone needing this for existing Node.js versions (all the way back to 0.10): https://github.com/sindresorhus/user-info |
rvagg commented Apr 14, 2016
Can someone justify this please? Most of this doesn't make sense cross-platform and as @bnoordhuis has pointed out we already expose most of these properties. Can we please not just implement things here because libuv does, we need to have more discipline than that. Too many tiny new features are getting in just because we can without much attention paid to is it worth it. |
rvagg commented Apr 14, 2016
Adding a temporary
I'm not a fan of this and would personally prefer a revert. |
silverwind commented Apr 14, 2016 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
I too feel that the added functionality seems rather unnecessary and that it was landed too fast without enough consensus. |
jasnell commented Apr 15, 2016 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Can't really agree with the "landed too fast" part. The PR was opened 8 days ago and landed 2 days ago. The standard rule in the collaborator's guide is 48/72 hours (weekday/weekend). We've had plenty of stuff land in far less time. While I can certainly understand regarding the not enough consensus part, given that I'm the only one who gave it an LGTM, it cannot be said that there wasn't enough time to review it. On the consensus part, this was looked at by six people, four of whom are CTC, none of whom objected. Again, we've had stuff land with less. That said, @rvagg makes a fair request with regards to use case. For my part, I consider this an ok fix for #5582because it does not change the existing behavior of bash-3.2$ sudo -u root ./node -pe "require('os').userInfo()"{uid: 0, gid: 0, username: 'root', homedir: '/var/root', shell: '/bin/sh' } bash-3.2$ sudo -u root ./node -pe "require('os').homedir()" /Users/james bash-3.2$I agree that the |
jbergstroem commented Apr 15, 2016
(Sorry for joining post-merge as well) I feel that the new |
jasnell commented Apr 15, 2016 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
One thing to note is that, as it is currently implemented, Given the benchmark: 'use strict';constcommon=require('../common.js');constos=require('os');constbench=common.createBenchmark(main,{method: ['old','new'],millions: [2]});functionmain(conf){constn=+conf.millions*1e6;vari=0;switch(conf.method){case'old': bench.start();for(;i<n;i++){varm={user: process.env.USER,shell: process.env.SHELL,homedir: os.homedir(),gid: process.getgid(),uid: process.getuid()}}bench.end(n/1e6);break;case'new': bench.start();for(;i<n;i++){os.userInfo();}bench.end(n/1e6);break;default: thrownewError('Unexpected');}}We see: If I modify the const_userInfo={};exports.userInfo=function(options={encoding: 'utf'}){if(typeofoptions==='string')options={encoding: options};if(!_userInfo[options.encoding]){_userInfo[options.encoding]=binding.getUserInfo(options);}return_userInfo[options.encoding];}The benchmark changes to: Given that it's not likely that this function will be called multiple times within a single process, however, the benchmark itself (and adding caching) may be of little value. |
os.userInfo() calls libuv's uv_os_get_passwd() function. It returns an object containing the current effective user's username, uid, gid, shell, and home directory. On Windows, the uid and gid are -1, and the shell is null. Refs: #5582 PR-URL: #6104 Reviewed-By: James M Snell <[email protected]>
Fishrock123 commented Apr 27, 2016
This landed in v6, and as far as I can tell should not have. Should we issue a revert? (Getting in was a bug of our release process, by the sounds of it.) |
ChALkeR commented Apr 27, 2016 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
@Fishrock123 Strictly speaking, reverting a semver-minor feature would be a semver-major… Or is this feature broken? |
addaleax commented Apr 27, 2016
This feature is not broken, and I agree, fully removing this in v6 is probably not a good idea. |
Fishrock123 commented Apr 27, 2016
We should deprecate it in the docs then. |
Fishrock123 commented Apr 27, 2016
No-one is significantly using it yet, so we can do that immediately. |
jasnell commented Apr 27, 2016
It should go through the normal deprecation dance if anything. I certainly disagree with the sentiment that it shouldn't have landed in v6. It was part of master, it landed through the normal processes, there was no revert PR before v6. |
Checklist
Affected core subsystem(s)
os
Description of change
os.getpw()calls libuv'suv_os_get_passwd()function. It returns an object containing the current effective user'susername,uid,gid,shell, andhomedir. On Windows, theuidandgidare-1, and theshellisnull.