-
-
Notifications
You must be signed in to change notification settings - Fork 120
feat: prefer os specific config dirs #616
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for starting the work on this
|
||
home, err := os.UserHomeDir() | ||
if err != nil { | ||
home = "." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given my last comment it would be "covered"/"used" as the latest fallback so I would not use it here (inverting the condition and use the legacy only if present)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand. "home" here is just a fallback in case anything goes wrong with the detection?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... a more proper way would be to use os.Getwd() I guess
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my point is that we have to handle a global fallback case if everything fails.
this is the .
case.
because we will handle it as a last resort anyway, we don't have to deal with it here, which allows for early returns without variables leaking or inaccurate naming (the naming is inaccurate in the last return legacy
in the sense it is a fallback not necessarily a legacy path). eg, something as:
// use the old path if it exists already
if home, err := os.UserHomeDir(); err != nil {
legacyPath := filepath.Join(home, "."+confDir)
if _, err := os.Stat(legacyPath); !os.IsNotExist(err) {
return legacyPath
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thanks for the explanation. "home" at this point was the base for the following legacy folder check and also the check for a macos ~/.config
. I guess if we remove the macos stuff this can go too.
If we include this like your proposal though, legacyPath will be needed again in the last return.
util/util.go
Outdated
|
||
// macos only: if $HOME/.config exist, prefer that over 'Library/Application Support' | ||
if runtime.GOOS == "darwin" { | ||
dotconf := filepath.Join(home, ".config") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this check is not strict enough and might make the $HOME/.config
directory be used without the user "consent". If an application creates a directory at any point, the CLI will start to use the previous directory without the user knowing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is true, and it already crossed my mind. As we have no way to keep track of the last used path (and also it would be out of scope here), I removed this check.
Closes #133