Repository navigation
Use os.UserHomeDir() instead of homedir.Dir() - #2429
linzhengen wants to merge 1 commit into
Conversation
|
Hi, As per our contributing docs we don't accept PRs that don't correspond to an existing issue. Without that or even a PR description, it's impossible to discern the intent or context of this PR. Closing, but can reopen if it's updated. |
| "/etc/ssh/ssh_config", | ||
| } | ||
| if homedir, err := homedir.Dir(); err == nil { | ||
| if homedir, err := os.UserHomeDir(); err == nil { |
There was a problem hiding this comment.
We usually prefer to use stdlib over adding dependencies. In this case, though, we used go-homedir in production for almost a year now, and if we're going to change it now, we have to consider potential implications to backwards-compatibility.
The first thing I would ask is: are homedir.Dir() and os.UserHomeDir() functionality equivalent for the purposes of our users? To answer that, sometimes it's best to view the source code:
homedir.Dir()https://github.com/mitchellh/go-homedir/blob/v1.1.0/homedir.go#L89-L167os.UserHomeDir()https://github.com/golang/go/blob/release-branch.go1.15/src/os/file.go#L489-L510
As we can see, their implementations are vastly different: homedir falls back to HOMEDRIVE + HOMEPATH on Windows #1948 (comment), to dscl -q . -read /Users/"$(whoami)" NFSHomeDirectory on Darwin, to getent passwd on Linux, and to sh -c "cd && pwd" when all else fails.
If we switch now, we have to be conscious that gh will appear broken—more precisely, it will lose the user's existing config & authentication credentials—for anyone who currently relies on these fallbacks. Unfortunately, we have no ability to tell who will be affected in advance.
Personally, now that I look at it, I think that mitchellh/go-homedir is doing too much, and I'd be happy to move away from it. We inherited its use from a codebase that was written before os.UserHomeDir() was added to Go.
Maybe it would be worth to risk it and handle user reports if they come in telling them that they must set %userprofile% on Windows or HOME on other platforms. But we'd have to discuss first. For now, I agree with @vilmibm's call to close this until there is more discussion/context around the proposed change. Tip for the future: PRs are more likely to get accepted if they have a description arguing for why the change might be valuable to the project. 🙇
No description provided.