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

use current work dir or temp dir to avoid ConfigDir error #60

Closed
zuoRambo opened this issue Nov 7, 2017 · 4 comments
Closed

use current work dir or temp dir to avoid ConfigDir error #60

zuoRambo opened this issue Nov 7, 2017 · 4 comments

Comments

@zuoRambo
Copy link
Contributor

zuoRambo commented Nov 7, 2017

unable to get current user home directory: os/user lookup failed; $HOME is empty

I build my application on instance A and run it on instance B.
The app run as user root and the env variable $HOME is /root.
But i got the follow error.

Maybe we should use temp dir

func ConfigDir() (string, error) {
	if runtime.GOOS == "windows" {
		return filepath.Join(os.Getenv("APPDATA"), "gops"), nil
	}
	homeDir := guessUnixHomeDir()
	if homeDir == "" {
                // os.TempDir() or filepath.Abs(filepath.Dir(os.Args[0]))
		return "", errors.New("unable to get current user home directory: os/user lookup failed; $HOME is empty")
	}
	return filepath.Join(homeDir, ".config", "gops"), nil
}
@zuoRambo
Copy link
Contributor Author

zuoRambo commented Nov 8, 2017

In production environment, the process's user is www and is nologin, In this case, the $HOME is not available.

@rakyll
Copy link
Member

rakyll commented Nov 8, 2017

Can we just make the ConfigDir configurable via an env? Current directory is not the most optimal solution either. You don't want to cd into a specific directory to be able to run gops.

/cc @odeke-em

@odeke-em
Copy link
Collaborator

odeke-em commented Nov 9, 2017

I totally agree with what @rakyll said, we can either check if it is configured first, then fallback to $HOME.

@zuoRambo
Copy link
Contributor Author

Thank you @odeke-em for the help and @rakyll for the reviews!

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

No branches or pull requests

3 participants