Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
Loading
from

Conversation

tjblackheart
Copy link

Closes #133

@tjblackheart tjblackheart changed the title prefer os specific config dirs feat: prefer os specific config dirs May 16, 2025
Copy link
Member

@tucksaun tucksaun left a 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

util/util.go Outdated Show resolved Hide resolved
util/util.go Show resolved Hide resolved
util/util.go Outdated Show resolved Hide resolved
util/util.go Outdated Show resolved Hide resolved
util/util.go Outdated Show resolved Hide resolved

home, err := os.UserHomeDir()
if err != nil {
home = "."
Copy link
Member

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)

Copy link
Author

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?

Copy link
Author

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

Copy link
Member

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
	}
}

Copy link
Author

@tjblackheart tjblackheart May 20, 2025

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")
Copy link
Member

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.

Copy link
Author

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.

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

Successfully merging this pull request may close these issues.

Use system config folder to store files
3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.