Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Is this still relevant? #34

Open
sathishvj opened this issue Sep 19, 2023 · 4 comments
Open

Is this still relevant? #34

sathishvj opened this issue Sep 19, 2023 · 4 comments

Comments

@sathishvj
Copy link

The os package code seems to be almost the very same. So, is this package still relevant? Or is the std lib os still using cgo somewhere?

From package os.

func UserHomeDir() (string, error) {
	env, enverr := "HOME", "$HOME"
	switch runtime.GOOS {
	case "windows":
		env, enverr = "USERPROFILE", "%userprofile%"
	case "plan9":
		env, enverr = "home", "$home"
	}
	if v := Getenv(env); v != "" {
		return v, nil
	}
	// On some geese the home directory is not always defined.
	switch runtime.GOOS {
	case "android":
		return "/sdcard", nil
	case "ios":
		return "/", nil
	}
	return "", errors.New(enverr + " is not defined")
}
@dolmen
Copy link

dolmen commented Mar 21, 2024

os.UserHomeDir() appeared with Go 1.12.

@dolmen
Copy link

dolmen commented Mar 21, 2024

Also the primary motivation for this package (from README.md) what that os/user was using cgo on Darwin. But since Go 1.20 this is no longer the case (see golang/go@185766d) and os/user even exposes a osusergo build tag to force avoiding cgo.

@PeterCardenas
Copy link

i went down this rabbit hole of finding this repo after seeing it in autocomplete 😅. I would appreciate if this repo was archived so that it's more obvious that this shouldn't be used

@dolmen
Copy link

dolmen commented Jul 3, 2024

Here is a 5 years old official answer from @mitchellh in #20 (comment):

I noted this somewhere else but can't find it... but the Go stdlib implementation is quite simplistic. It only checks env vars. This will work in most cases (90+%?) so if it works for you that's great and you can remove a dep!

In the nearly decade (!!!) we've had some of our software like Vagrant, there has been enough situations where that is not enough so we have extra logic here in go-homedir to try other ways to detect the home directory. We haven't had a bug reported in home directory detection in a long time...

So if you want something more robust then keep using this lib, otherwise you can use the stdlib!

While I appreciate the effort made here, the stdlib implementation continued to evolve while this repo is unmaintained.

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

No branches or pull requests

3 participants