Skip to content

Feat/respect xdg spec on all os #2627

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

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

KlassyKat
Copy link

This Pull Request fixes/closes #1498.

It changes the following:

  • Unifies OS logic for loading config.
  • Adds a ordered list of locations to search for config.
  • List includes XDG_CONFIG_HOME as the first priority.
  • Implements the same logic for getting the cache_path with XDG_CACHE_HOME as the top priority
  • No longer creates an empty gitui config folder by default.

I followed the checklist:

  • I added unittests
  • I ran make check without errors
  • I tested the overall application
  • I added an appropriate item to the changelog

I am a bit hesitant about this change since I am unsure if any logic
depends on a config folder needing to exist. But as far as I can tell
nothing does and creating a empty config folder in someones dotfiles
when they don't want any configuration for gitui seems like terrible UX.
@KlassyKat
Copy link
Author

KlassyKat commented Apr 29, 2025

No longer creates an empty gitui config folder by default.

I'm a little trepidatious about this particular change since I am not certain there is no logic relying on a config folder existing; though as far as I can tell there isn't.

If it doesn't present any issues (or even if it does present minor issues) I am a strong advocate for not forcing an empty gitui config folder to exist for any users that don't feel any need to configure gitui. I see this as an extremely annoying UX for anyone that doesn't want/feel the need for any configuration of gitui and likes to keep their dotfiles clean.

For an app as functional as gitui out of the box I don't see the portion of users who don't feel the need for any additional config as a particularly small group.

@KlassyKat
Copy link
Author

KlassyKat commented Apr 29, 2025

Could also add a $GITUI_CONFIG_DIR env var to look for at the top of the priority list, but I see that as maybe a bit overkill for what is a relatively simple config structure.

Copy link
Contributor

@naseschwarz naseschwarz 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 your PR!

I'm not a regular Windows user, so I didn't test the new behavior. The following is just based on code review.

I'm a little trepidatious about this particular change since I am not certain there is no logic relying on a config folder existing; though as far as I can tell there isn't.

I agree with that. There was a feature that created a null theme file a while back, but that has been removed in #1652. No need to create an empty directory.

I have a few remarks regarding the implementation.

src/args.rs Outdated
dirs::config_dir()
// List of potential config directories in order of priority
let config_dir_candidates = [
env::var_os("XDG_CONFIG_HOME").map(PathBuf::from),
Copy link
Contributor

Choose a reason for hiding this comment

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

At least according to spec, XDG_CONFIG_HOME should only be considered if it's absolute. (Same for _CACHE...)

Comment on lines +157 to +158
for potential_dir in
candidates.into_iter().flatten().filter(|p| p.is_dir())
Copy link
Contributor

@naseschwarz naseschwarz Apr 30, 2025

Choose a reason for hiding this comment

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

Sorry, one more remark: At least for XDG, Path::is_dir isn't a precondition for considering that path. If it doesn't exist, create it (with permissions 0700)

Copy link
Author

Choose a reason for hiding this comment

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

If, when attempting to write a file, the destination directory is non-existent an attempt should be made to create it with permission 0700.

This only applies when attempting to write a file.

When attempting to read a file, if for any reason a file in a certain directory is unaccessible, e.g. because the directory is non-existent, the file is non-existent or the user is not authorized to open the file, then the processing of the file in that directory should be skipped.

So believe this point is fairly moot when it comes to XDG_CONFIG_HOME.

That being said it does have some consideration for XDG_CACHE_HOME, but I think there is still some room for interpretation. I think you could consider that line to be referring to the creation of an app subdirectory and not to create the root directory itself. In which case that is already being done. Furthermore when it comes to creating good UX a user may have an XDG_CACHE_HOME defined which would result in that being the location to write to by default. But say the user wanted to keep XDG_CACHE_HOME only having the logs of particular apps creating a gitui folder in the fallback cache directory would allow them to filter it out.

I don't really imagine anyone wanting to do that, but it seems superior to have the option than not to.

Copy link
Contributor

@naseschwarz naseschwarz May 2, 2025

Choose a reason for hiding this comment

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

Yes, for XDG_CONFIG_HOME it does not make a difference as of now, as we don't create things there. For XDG_CACHE_HOME it does, though.

It worked before and does not work now. I'm sorry to say, but I don't think I'd want to approve this. If this were to fix a huge issue, okay, but this only addresses a (very) peculiar concern on windows.

@KlassyKat KlassyKat marked this pull request as draft May 2, 2025 01:20
@KlassyKat KlassyKat marked this pull request as ready for review May 2, 2025 10:04
@KlassyKat KlassyKat requested a review from naseschwarz May 2, 2025 10:58
@naseschwarz naseschwarz removed their request for review May 2, 2025 12:41
@KlassyKat KlassyKat marked this pull request as draft May 3, 2025 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Follow XDG spec on windows
2 participants