Use actual home directory for LaunchServices plist#24
Conversation
|
I’ve refactored this section of the code so it can be tested. Could you please rebase on current main? |
8cb0d31 to
b7612cb
Compare
grahamgilbert
left a comment
There was a problem hiding this comment.
I think the home directory should become part of Client, following the existing option pattern, rather than being passed around separately. That keeps the client state coherent and makes the default plist path a derived value from the client.
For example:
type Client struct {
Runner osq.CmdRunner
HomeDir string
PlistLocation string
}
func WithHomeDir(homeDir string) Option {
return func(c *Client) {
c.HomeDir = homeDir
}
}
Then NewClient() can populate HomeDir from the current user by default, and PlistLocation can be derived from c.HomeDir unless WithPlistLocation(...) was provided.
I’d also prefer deriving the default home directory from user.Current().HomeDir rather than calling os.UserHomeDir() separately. user.Current() already gives us both the username and home directory, so keeping them from the same lookup avoids subtle mismatches.
Suggested behavior:
- default
NewClient()setsHomeDirfrom the current user and uses it for the LaunchServices plist path WithHomeDir("/Volumes/foo/Users/bob")setsClient.HomeDirand uses that for the plist pathWithPlistLocation(...)still overrides everything
Fixes handling for macOS accounts whose home directories are not under
/Users/$USER.default-browsercurrently constructs the LaunchServices plist path using/Users/<username>. That fails for accounts whoseNFSHomeDirectorypoints to another volume, for example:In that case, running default-browser --identifier ... fails while trying to create /Users/.
This change uses os.UserHomeDir() when constructing the default LaunchServices plist path, while preserving the existing WithPlistLocation override behavior.