GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — os: add .homedir() by robertkowalski · Pull Request #1670 · nodejs/node

Conversation

@robertkowalski

@robertkowalski robertkowalski commented May 10, 2015

Copy link
Copy Markdown
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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@robertkowalski
os: add .homedir()
8cf14ee
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

trevnorris commented May 10, 2015

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Fishrock123

Fishrock123 commented May 10, 2015

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@fivdi

fivdi commented May 10, 2015

Copy link
Copy Markdown

See also user-home

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

robertkowalski commented May 10, 2015

Copy link
Copy Markdown
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)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Fishrock123

Fishrock123 commented May 10, 2015

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@domenic

domenic commented May 10, 2015

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ChALkeR

ChALkeR commented May 10, 2015

Copy link
Copy Markdown
Member

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?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cjihrig

cjihrig commented May 10, 2015

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vkurchatkin

vkurchatkin commented May 10, 2015

Copy link
Copy Markdown
Contributor

prior discussion: #682

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sindresorhus

sindresorhus commented May 10, 2015

Copy link
Copy Markdown

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@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

rvagg commented May 11, 2015

Copy link
Copy Markdown
Member

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!).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@piscisaureus

piscisaureus commented May 11, 2015

Copy link
Copy Markdown
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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cjihrig

cjihrig commented May 11, 2015

Copy link
Copy Markdown
Contributor

@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?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@piscisaureus

piscisaureus commented May 11, 2015

Copy link
Copy Markdown
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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cjihrig

cjihrig commented May 11, 2015

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@trevnorris

trevnorris commented May 11, 2015

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@domenic

domenic commented May 11, 2015

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cjihrig cjihrig mentioned this pull request May 12, 2015
WIP: unix,win: add uv_homedir() libuv/libuv#350
Closed
@Fishrock123

Fishrock123 commented May 21, 2015

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cjihrig

cjihrig commented May 21, 2015

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

robertkowalski commented May 21, 2015

Copy link
Copy Markdown
Contributor Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cjihrig cjihrig mentioned this pull request May 25, 2015
os: add homedir() #1791
Merged
@Fishrock123

Fishrock123 commented May 25, 2015

Copy link
Copy Markdown
Contributor

Closing in favor of #1791

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Fishrock123 Fishrock123 closed this May 25, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

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

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

13 participants

@robertkowalski @trevnorris @Fishrock123 @fivdi @domenic @ChALkeR @cjihrig @vkurchatkin @sindresorhus @rvagg @piscisaureus @mscdex @brendanashworth
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.