mitchellh/go-homedir

Is this still relevant?

Opened this issue · 4 comments

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")
}

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.

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

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.