Skip to content

Conversation

dolmen
Copy link

@dolmen dolmen commented Mar 25, 2024

Note: This change applies to code compiled only for darwin, but it also allows to remove a dependency from go.mod which will ease maintenance of downstream projects for any platforms.

Use os.UserHomeDir() which is available since go1.12 (already the minimum go version for this project). This allows to drop the dependency on github.com/mitchellh/go-homedir which was needed only for Darwin.

go-homedir still has the following features on Darwin:

  • tries very hard to get the location of the home directory when $HOME is not set
  • avoids use of os/user which dependended on cgo until go1.20

I don't think we really need to go beyond $HOME. However if we really wanted it we could now use os/user.Current() as since go1.20 it uses the libc on Darwin and no longer needs cgo on any platform. So we should drop go-homedir anyway.

This change applies to code compiled only for darwin, but it also allows
to remove a dependency from go.mod which will ease maintenance of
downstream projects for any platforms.

Use os.UserHomeDir() which is available since go1.12 (already the
minimum go version for this project). This allows to drop the dependency
on github.com/mitchellh/go-homedir which was needed only for Darwnin.

go-homedir still has the following features:
* tries very hard to get the location of the home directory when $HOME
  is not set
* avoids use of os/user which dependended on cgo until go1.20

I don't think we really need to go beyond $HOME, but if we really wanted
it we could now use os/user.Current() as since go1.20 it uses the libc on
Darwin and no longer needs cgo on any platform.
@ne0h
Copy link

ne0h commented Jul 9, 2024

Any progress here? Change would be appreciated!

@mallikabandaru mallikabandaru requested a review from Copilot March 10, 2025 08:38
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This pull request updates the code to use os.UserHomeDir() instead of the external go-homedir dependency, reducing external dependencies and simplifying maintenance for Darwin builds.

  • Replaces go-homedir.Dir() with os.UserHomeDir().
  • Removes the dependency on github.com/mitchellh/go-homedir from the imports.

Reviewed Changes

File Description
rootcerts_darwin.go Updated to use os.UserHomeDir() and removed go-homedir dependency.

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

rootcerts_darwin.go:43

  • Consider using filepath.Join instead of path.Join for constructing file system paths to ensure more robust handling of OS path conventions.
loginKeychain := path.Join(home, "Library", "Keychains", "login.keychain")

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.

2 participants