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

Prefer $HOME on all platforms #3000

Merged
merged 2 commits into from
Sep 17, 2024
Merged

Prefer $HOME on all platforms #3000

merged 2 commits into from
Sep 17, 2024

Conversation

DrJosh9000
Copy link
Contributor

Description

#2990 is good, but is likely to be a breaking change on Windows particularly. For instance the Elastic CI Stack runs the agent with HOME=C:\buildkite-agent.

Rather than revert #2990, in the spirit of Go Proverbs I propose we do a little copying instead of a little dependency.

Changes

  • Rename internal/utils to internal/osutil, which suits it a little better.
  • Add osutil.UserHomeDir, which wraps os.UserHomeDir and prefers $HOME when available.

Testing

  • Tests have run locally (with go test ./...). Buildkite employees may check this if the pipeline has run automatically.
  • Code is formatted (with go fmt ./...)

// over other options (such as USERPROFILE on Windows).
func UserHomeDir() (string, error) {
h := os.Getenv("HOME")
if h != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any preference of this style over?:

	if h := os.Getenv("HOME"); h != "" {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, in fact I think we should prefer it that way. Just hammered out the code quickly.

@DrJosh9000 DrJosh9000 merged commit b00fade into main Sep 17, 2024
1 check passed
@DrJosh9000 DrJosh9000 deleted the fix-homedir branch September 17, 2024 06:39
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

Successfully merging this pull request may close these issues.

3 participants