Skip to content
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

os: add .homedir() #1670

Closed
wants to merge 1 commit into from
Closed

os: add .homedir() #1670

wants to merge 1 commit into from

Conversation

robertkowalski
Copy link
Contributor

In almost every cli-client that I write I need the current homedir
at a certain point.

While we have a function for getting the directory for storing
temporary files (callled tmpdir), a function for receiving the
location of the home directory is still missing.

In almost every cli-client that I write I need the current homedir
at a certain point.

While we have a function for getting the directory for storing
temporary files (callled `tmpdir`), a function for receiving the
location of the home directory is still missing.
@trevnorris
Copy link
Contributor

What happens if process.env.{HOME,USERPROFILE} isn't set?

@Fishrock123
Copy link
Contributor

I think this could be useful if there is a reliable and robust implementation.

@fivdi
Copy link

fivdi commented May 10, 2015

See also user-home

@mscdex mscdex added the os Issues and PRs related to the os subsystem. label May 10, 2015
@robertkowalski
Copy link
Contributor Author

oh good points, i just took a look at user-home

maybe it makes sense to take the code from https://github.com/sindresorhus/user-home/blob/master/index.js and add a notice t our LICENSE file (it is MIT)

@Fishrock123
Copy link
Contributor

Then again, if userland can do this fine, why should it be in core?

@domenic
Copy link
Contributor

domenic commented May 10, 2015

I am definitely +1 on including something like this, although indeed it seems this might not be robust enough of an implementation.

@ChALkeR
Copy link
Member

ChALkeR commented May 10, 2015

Should it not throw an Error instead of returning null or undefined (user-home returns null, your code returns undefined) when the home directory couldn't be determined?

@cjihrig
Copy link
Contributor

cjihrig commented May 10, 2015

I don't think this should be done using environment variables. There are existing C APIs for this, right?

@vkurchatkin
Copy link
Contributor

prior discussion: #682

@sindresorhus
Copy link

I strongly feel this should have a robust implementation in libuv instead of just checking process.env => libuv/libuv#11

The ecosystem use the home dir for so many different things, but the current userland ways of inferring it are just too fragile.

@brendanashworth brendanashworth added the semver-minor PRs that contain new features and should be released in the next minor version. label May 10, 2015
@rvagg
Copy link
Member

rvagg commented May 11, 2015

As per the previous discussion in #682 (my comment specifically: #682 (comment)) and echoing @sindresorhus' comment above; I'm -1 on this unless we can come up with a solid cross-platform implementation that doesn't involve a lot of guesswork. The main reason the previous 2 persistent-history for REPL PRs didn't make it in is because they came bundled with implementations like this and @chrisdickinson found a good compromise of just removing the need for a homedir completely--it'd be nice if we could move to using a homedir but the current solution(s) are unsatisfactory. When we expose an API like this to users we are suggesting that it's reliable, but it's absolutely not (sadly!).

@piscisaureus
Copy link
Contributor

I think an API to retrieve the home directory would be an acceptable addition to libuv.

The implementation is also not that hard - on unix the proper way would be to to call getpwnam(3) and return the pw_dir member from the returned struct passwd*.

On Windows the implementation would use SHGetKnowFolderPath and to retrieve the FOLDERID_Profile value.

@cjihrig
Copy link
Contributor

cjihrig commented May 11, 2015

@piscisaureus I have already done that. Would you mind looking over https://github.com/cjihrig/userinfo and letting me know if that would be suitable for libuv?

@piscisaureus
Copy link
Contributor

@cjihrig

That looks pretty good in general.
I could comment a bit (use GetUsernameW), but reviewing it in depth makes little sense since it's not a libuv patch.

@cjihrig
Copy link
Contributor

cjihrig commented May 11, 2015

OK, thanks. I'll work on something for libuv.

@trevnorris
Copy link
Contributor

@piscisaureus What if the home directory doesn't exist?

@domenic
Copy link
Contributor

domenic commented May 11, 2015

Well I think the precedent for other os APIs has been to return 0 in that case ... ;)

@Fishrock123
Copy link
Contributor

Landed in libuv: libuv/libuv@a62c2d5 \o/

@cjihrig
Copy link
Contributor

cjihrig commented May 21, 2015

I'll work on the io.js bits soon and PR it once it's in deps/libuv.

@Fishrock123 Fishrock123 added the libuv Issues and PRs related to the libuv dependency or the uv binding. label May 21, 2015
@robertkowalski
Copy link
Contributor Author

i'll just keep this open for reference / further discussion, please close it once @cjihrig has a superseeding PR

@cjihrig cjihrig mentioned this pull request May 25, 2015
@Fishrock123
Copy link
Contributor

Closing in favor of #1791

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libuv Issues and PRs related to the libuv dependency or the uv binding. os Issues and PRs related to the os subsystem. semver-minor PRs that contain new features and should be released in the next minor version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.