[calamares] Use XDG_{DATA,CONFIG}_DIRS as appropriate

- Use DATA for the qml and branding directories (looks for qml/
   and branding/<name>/ in those directories).
 - Use CONFIG for the global settings and module settings (looks
   for settings.conf and module/<name>/ in those directories).

FIXES #941
main
Adriaan de Groot 6 years ago
parent c489320af5
commit 3b8d2835e0

@ -145,6 +145,9 @@ qmlDirCandidates( bool assumeBuilddir )
{ {
if ( assumeBuilddir ) if ( assumeBuilddir )
qmlDirs << QDir::current().absoluteFilePath( "src/qml" ); // In build-dir qmlDirs << QDir::current().absoluteFilePath( "src/qml" ); // In build-dir
if ( CalamaresUtils::haveExtraDirs() )
for ( auto s : CalamaresUtils::extraDataDirs() )
qmlDirs << ( s + QML );
qmlDirs << CalamaresUtils::appDataDir().absoluteFilePath( QML ); qmlDirs << CalamaresUtils::appDataDir().absoluteFilePath( QML );
} }
@ -164,6 +167,9 @@ settingsFileCandidates( bool assumeBuilddir )
{ {
if ( assumeBuilddir ) if ( assumeBuilddir )
settingsPaths << QDir::current().absoluteFilePath( settings ); settingsPaths << QDir::current().absoluteFilePath( settings );
if ( CalamaresUtils::haveExtraDirs() )
for ( auto s : CalamaresUtils::extraConfigDirs() )
settingsPaths << ( s + settings );
settingsPaths << CMAKE_INSTALL_FULL_SYSCONFDIR "/calamares/settings.conf"; // String concat settingsPaths << CMAKE_INSTALL_FULL_SYSCONFDIR "/calamares/settings.conf"; // String concat
settingsPaths << CalamaresUtils::appDataDir().absoluteFilePath( settings ); settingsPaths << CalamaresUtils::appDataDir().absoluteFilePath( settings );
} }
@ -182,6 +188,9 @@ brandingFileCandidates( bool assumeBuilddir, const QString& brandingFilename )
{ {
if ( assumeBuilddir ) if ( assumeBuilddir )
brandingPaths << ( QDir::currentPath() + QStringLiteral( "/src/" ) + brandingFilename ); brandingPaths << ( QDir::currentPath() + QStringLiteral( "/src/" ) + brandingFilename );
if ( CalamaresUtils::haveExtraDirs() )
for ( auto s : CalamaresUtils::extraDataDirs() )
brandingPaths << ( s + brandingFilename );
brandingPaths << QDir( CMAKE_INSTALL_FULL_SYSCONFDIR "/calamares/" ).absoluteFilePath( brandingFilename ); brandingPaths << QDir( CMAKE_INSTALL_FULL_SYSCONFDIR "/calamares/" ).absoluteFilePath( brandingFilename );
brandingPaths << CalamaresUtils::appDataDir().absoluteFilePath( brandingFilename); brandingPaths << CalamaresUtils::appDataDir().absoluteFilePath( brandingFilename);
} }

@ -97,12 +97,23 @@ setAppDataDir( const QDir& dir )
s_isAppDataDirOverridden = true; s_isAppDataDirOverridden = true;
} }
/* Split $ENV{@p name} on :, append to @p l, making sure each ends in / */
static void
mungeEnvironment( QStringList& l, const char *name )
{
for ( auto s : QString( qgetenv( name ) ).split(':') )
if ( s.endsWith( '/' ) )
l << s;
else
l << ( s + '/' );
}
void void
setXdgDirs() setXdgDirs()
{ {
s_haveExtraDirs = true; s_haveExtraDirs = true;
s_extraConfigDirs.append( QString( qgetenv( "XDG_CONFIG_DIRS" ) ).split(':') ); mungeEnvironment( s_extraConfigDirs, "XDG_CONFIG_DIRS" );
s_extraDataDirs.append( QString( qgetenv( "XDG_DATA_DIRS" ) ).split(':') ); mungeEnvironment( s_extraDataDirs, "XDG_DATA_DIRS" );
} }
QStringList QStringList
@ -121,7 +132,11 @@ extraDataDirs()
return QStringList(); return QStringList();
} }
bool
haveExtraDirs()
{
return s_haveExtraDirs && ( !s_extraConfigDirs.isEmpty() || !s_extraDataDirs.isEmpty() );
}
bool bool
isAppDataDirOverridden() isAppDataDirOverridden()

@ -80,10 +80,13 @@ namespace CalamaresUtils
DLLEXPORT void setQmlModulesDir( const QDir& dir ); DLLEXPORT void setQmlModulesDir( const QDir& dir );
/** @brief Setup extra config and data dirs from the XDG variables. /** @brief Setup extra config and data dirs from the XDG variables.
*
*/ */
DLLEXPORT void setXdgDirs(); DLLEXPORT void setXdgDirs();
/** @brief Are any extra directories configured? */
DLLEXPORT bool haveExtraDirs();
/** @brief XDG_CONFIG_DIRS, each guaranteed to end with / */
DLLEXPORT QStringList extraConfigDirs(); DLLEXPORT QStringList extraConfigDirs();
/** @brief XDG_DATA_DIRS, each guaranteed to end with / */
DLLEXPORT QStringList extraDataDirs(); DLLEXPORT QStringList extraDataDirs();
/** /**

@ -155,6 +155,10 @@ moduleConfigurationCandidates( bool assumeBuildDir, const QString& moduleName, c
if ( assumeBuildDir && configFileName.contains( '/' ) ) if ( assumeBuildDir && configFileName.contains( '/' ) )
paths << QDir().absoluteFilePath( configFileName ); paths << QDir().absoluteFilePath( configFileName );
if ( CalamaresUtils::haveExtraDirs() )
for ( auto s : CalamaresUtils::extraConfigDirs() )
paths << ( s + QString( "modules/%1" ).arg( configFileName ) );
paths << QString( "/etc/calamares/modules/%1" ).arg( configFileName ); paths << QString( "/etc/calamares/modules/%1" ).arg( configFileName );
paths << CalamaresUtils::appDataDir().absoluteFilePath( QString( "modules/%1" ).arg( configFileName ) ); paths << CalamaresUtils::appDataDir().absoluteFilePath( QString( "modules/%1" ).arg( configFileName ) );
} }

Loading…
Cancel
Save