From caba74438ecf234d9dcf12ccd2abf23b8948678e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 2 Apr 2019 09:57:28 -0400 Subject: [PATCH] [libcalamares] Improve XDG handling - When environment is empty, use default values from spec - Search in application-named subdirs first (but keep previous behavior of also searching directly in the named dirs) - Don't consider empty XDG_* elements - Settings XDG_DATA_DIRS=":" would yield an empty list of extra directories to check; don't bother setting haveExtraDirs for that. --- src/libcalamares/utils/CalamaresUtils.cpp | 25 ++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/libcalamares/utils/CalamaresUtils.cpp b/src/libcalamares/utils/CalamaresUtils.cpp index 3ab758522..4a8b1f528 100644 --- a/src/libcalamares/utils/CalamaresUtils.cpp +++ b/src/libcalamares/utils/CalamaresUtils.cpp @@ -99,21 +99,32 @@ setAppDataDir( const QDir& dir ) /* Split $ENV{@p name} on :, append to @p l, making sure each ends in / */ static void -mungeEnvironment( QStringList& l, const char *name ) +mungeEnvironment( QStringList& l, const char* name, const char* defaultDirs ) { - for ( auto s : QString( qgetenv( name ) ).split(':') ) + static const QString calamaresSubdir = QStringLiteral( "calamares/" ); + + QStringList dirs = QString( qgetenv( name ) ).split( ':' ); + if ( dirs.isEmpty() ) + dirs = QString( defaultDirs ).split( ':' ); + + for ( auto s : dirs ) + { + if ( s.isEmpty() ) + continue; if ( s.endsWith( '/' ) ) - l << s; + l << ( s + calamaresSubdir ) << s; else - l << ( s + '/' ); + l << ( s + '/' + calamaresSubdir ) << ( s + '/' ); + } } void setXdgDirs() { - s_haveExtraDirs = true; - mungeEnvironment( s_extraConfigDirs, "XDG_CONFIG_DIRS" ); - mungeEnvironment( s_extraDataDirs, "XDG_DATA_DIRS" ); + mungeEnvironment( s_extraConfigDirs, "XDG_CONFIG_DIRS", "/etc/xdg" ); + mungeEnvironment( s_extraDataDirs, "XDG_DATA_DIRS", "/usr/local/share/:/usr/share/" ); + + s_haveExtraDirs = !( s_extraConfigDirs.isEmpty() && s_extraDataDirs.isEmpty() ); } QStringList