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: The result of UserHomeDir and User.HomeDir is inconsistent. #31070

Closed
Dreamacro opened this issue Mar 27, 2019 · 6 comments
Closed

os: The result of UserHomeDir and User.HomeDir is inconsistent. #31070

Dreamacro opened this issue Mar 27, 2019 · 6 comments

Comments

@Dreamacro
Copy link

@Dreamacro Dreamacro commented Mar 27, 2019

What version of Go are you using (go version)?

$ go version
go version go1.12 darwin/amd64

Does this issue reproduce with the latest release?

yes.

What did you do?

Before go 1.12, I used os/user to get homedir.

current, _ := user.Current()
current.HomeDir

After new release, I used new function UserHomeDir

homeDir, _ := os.UserHomeDir()

However, they may return different values under same environment. For example, when I used termux on android, the former returns $HOME while the latter returns /.

The root case because of the UserHomeDir returns / directly but user.Current() read env "$HOME" first.

I prefer the previous implementation. So how do you plan to deal with the inconsistency between the two implementation?

@cuonglm

This comment has been minimized.

Copy link
Contributor

@cuonglm cuonglm commented Mar 27, 2019

With commit bedb6a1 , the result is now consistent. But not when HOME is not set.:

  • current.HomeDir is /sdcard
  • os.UserHomeDir() returns /
@Dreamacro

This comment has been minimized.

Copy link
Author

@Dreamacro Dreamacro commented Mar 27, 2019

Great! But will this patch be released on 1.12.2? this is a long time for me to wait until 1.13 release 🤔

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Mar 27, 2019

Change https://golang.org/cl/169540 mentions this issue: os/user: keep user.HomeDir sync with os.UserHomeDir when HOME not set

@cuonglm

This comment has been minimized.

Copy link
Contributor

@cuonglm cuonglm commented Mar 27, 2019

@Dreamacro I don't know, you should ask the core team cc @bradfitz @mvdan

Not sure this issue is urgent for a cherry pick.

@bradfitz

This comment has been minimized.

Copy link
Contributor

@bradfitz bradfitz commented Mar 27, 2019

@mvdan

This comment has been minimized.

Copy link
Member

@mvdan mvdan commented Mar 27, 2019

But will this patch be released on 1.12.2? this is a long time for me to wait until 1.13 release

Cherry-picks are generally reserved for regressions, security bugs, or really bad bugs like runtime crashes, so I don't think this qualifies. If anyone really wants the fix before 1.13 is released, copy-pasting a bit of code from master should be pretty easy.

I think what @Gnouc said in his first comment makes sense. os/user depends on os, so perhaps we could even make it call os.UserHomeDir to deduplicate the logic.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.