Skip to content

Commit

Permalink
Reverse order for parsing files in XDG_CONFIG_DIRS
Browse files Browse the repository at this point in the history
https://specifications.freedesktop.org/basedir-spec/latest/
says precedence should be

XDG_CONFIG_HOME > 1st entry of XDG_CONFIG_DIRS > 2nd entry ...

EasyBuild had this reversed for XDG_CONFIG_DIRS

Fixes easybuilders#4582
  • Loading branch information
bartoldeman committed Sep 11, 2024
1 parent 56db19c commit 7790978
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion easybuild/tools/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def terminal_supports_colors(stream):
CONFIG_ENV_VAR_PREFIX = 'EASYBUILD'

XDG_CONFIG_HOME = os.environ.get('XDG_CONFIG_HOME', os.path.join(os.path.expanduser('~'), ".config"))
XDG_CONFIG_DIRS = os.environ.get('XDG_CONFIG_DIRS', '/etc/xdg').split(os.pathsep)
XDG_CONFIG_DIRS = os.environ.get('XDG_CONFIG_DIRS', '/etc/xdg').split(os.pathsep)[::-1]
DEFAULT_SYS_CFGFILES = [f for d in XDG_CONFIG_DIRS for f in sorted(glob.glob(os.path.join(d, 'easybuild.d', '*.cfg')))]
DEFAULT_USER_CFGFILE = os.path.join(XDG_CONFIG_HOME, 'easybuild', 'config.cfg')

Expand Down
2 changes: 1 addition & 1 deletion test/framework/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def test_XDG_CONFIG_env_vars(self):

# $XDG_CONFIG_HOME not set, multiple directories listed in $XDG_CONFIG_DIRS
del os.environ['XDG_CONFIG_HOME'] # unset, so should become default
os.environ['XDG_CONFIG_DIRS'] = os.pathsep.join([dir1, dir2, dir3])
os.environ['XDG_CONFIG_DIRS'] = os.pathsep.join([dir3, dir2, dir1])
cfg_files = [
os.path.join(dir1, 'easybuild.d', 'bar.cfg'),
os.path.join(dir1, 'easybuild.d', 'foo.cfg'),
Expand Down
4 changes: 2 additions & 2 deletions test/framework/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -3542,7 +3542,7 @@ def test_show_default_configfiles(self):

xdg_config_home = os.path.join(self.test_prefix, 'home')
os.environ['XDG_CONFIG_HOME'] = xdg_config_home
xdg_config_dirs = [os.path.join(self.test_prefix, 'etc', 'xdg'), os.path.join(self.test_prefix, 'moaretc')]
xdg_config_dirs = [os.path.join(self.test_prefix, 'moaretc'), os.path.join(self.test_prefix, 'etc', 'xdg')]
os.environ['XDG_CONFIG_DIRS'] = os.pathsep.join(xdg_config_dirs)

# put various dummy cfgfiles in place
Expand All @@ -3563,7 +3563,7 @@ def test_show_default_configfiles(self):
logtxt = read_file(self.logfile)
expected = expected_tmpl % (xdg_config_home, os.pathsep.join(xdg_config_dirs),
"%s => found" % os.path.join(xdg_config_home, 'easybuild', 'config.cfg'),
'{' + ', '.join(xdg_config_dirs) + '}',
'{' + ', '.join(xdg_config_dirs[::-1]) + '}',
', '.join(cfgfiles[:-1]), 4, ', '.join(cfgfiles))
self.assertIn(expected, logtxt)

Expand Down

0 comments on commit 7790978

Please sign in to comment.