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

@tucksaun tucksaun May 20, 2025

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.

Copy link
Author

Choose a reason for hiding this comment

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

Hey @tucksaun, you think we can finish up this little thing? If these mere 10 lines of code are somehow not up to your standard please say so and I just close it, no problem. If not, I don't see whats the hold up. Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

If we include this like your proposal though, legacyPath will be needed again in the last return.

No because the last return (acting as a fallback) would then be return "./." + confDir.

Overall this organisation is mostly nice for us maintainers because it means the if block handling the legacy path is only responsible for handling legacy, not the fallback:

  • we can have a warning about the use of the legacy path and the need to migrate
  • we only have to remove this block when we remove support for legacy config directories

Copy link
Author

Choose a reason for hiding this comment

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

No because the last return (acting as a fallback) would then be return "./." + confDir.

Which is exactly what legacyPath is set to beforehand in any case. But sure, i've changed it to a hardcoded path.

util/util.go Outdated Show resolved Hide resolved
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.