[Linux] Use XDG_CONFIG_HOME if it's defined

Remember, just because you request it, that doesn't mean you'll get it.

Moderator: GZDoom Developers

toxicbits
Posts: 8
Joined: Fri Sep 15, 2017 4:24 pm

[Linux] Use XDG_CONFIG_HOME if it's defined

Post by toxicbits »

GZDoom should use the path defined in the environment variable XDG_CONFIG_HOME and if it's not defined, fall back to ~/.config. Cf. the XDG Base Directory Specification: https://standards.freedesktop.org/based ... atest.html

This makes it easier to package. I've tried to fix this myself, but somehow configPath still contains ~/.config in the

Code: Select all

if (mkdir
block even if it should contain the value of the environment variable.
Examples of XDG_CONFIG_HOME usage:

https://github.com/chocolate-doom/choco ... 445e6365d5
https://github.com/Novum/vkQuake/pull/116/files

My patch:
Spoiler:
_mental_
 
 
Posts: 3812
Joined: Sun Aug 07, 2011 4:32 am

Re: [Linux] Use XDG_CONFIG_HOME if it's defined

Post by _mental_ »

We use GitHub pull requests for code contributions.
While small patches can be accepted, it's much easier to comment and review changes in PR.

For example, this patch cannot be used as is because:
  • It uses C++ IO streams for logging and it's pretty useless anyway in my opinion
  • It alters error reporting in a bad way and two consecutive I_FatalError() calls are simply wrong
Ubuntu versions I tried have no $XDG_CONFIG_HOME defined but only $XDG_CONFIG_DIRS environment variable.
toxicbits
Posts: 8
Joined: Fri Sep 15, 2017 4:24 pm

Re: [Linux] Use XDG_CONFIG_HOME if it's defined

Post by toxicbits »

We use GitHub pull requests for code contributions.
Yeah, I already submitted a pull request for another issue, but didn't in this case since this patch doesn't work (yet). I can clean it up and submit it, though.

I think in most cases, $XDG_CONFIG_HOME is not defined, but the spec states "$XDG_CONFIG_HOME defines the base directory relative to which user specific configuration files should be stored. If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used.".
User avatar
Chris
Posts: 2940
Joined: Thu Jul 17, 2003 12:07 am
Graphics Processor: ATI/AMD with Vulkan/Metal Support

Re: [Linux] Use XDG_CONFIG_HOME if it's defined

Post by Chris »

The main issues I see are places where you make a call like:

Code: Select all

if (NicePath("$XDG_CONFIG_HOME/").IsEmpty())
Even if XDG_CONFIG_HOME is empty or unset, the returned path would still contain an / which means it'll never be an empty result. Also a number of times you seem to make multiple NicePath calls with XDG_CONFIG_HOME as the base to test if it's set (this isn't performance-sensitive code, but still). A simple getenv should work, testing if it returns NULL or an empty string.

Relatedly, there is also a $XDG_CACHE_HOME in the XDG standard (with a fallback to $HOME/.cache), which might be better to use instead of "$XDG_CONFIG_HOME/zdoom/cache" or "$HOME/.config/zdoom/cache".
toxicbits
Posts: 8
Joined: Fri Sep 15, 2017 4:24 pm

Re: [Linux] Use XDG_CONFIG_HOME if it's defined

Post by toxicbits »

Ah, thanks. I didn't know getenv was part of the standard library. Will try that.
Post Reply

Return to “Feature Suggestions [GZDoom]”