[calamares] Refactor searching for settings.conf

- Split the collection of paths off from the search itself.
This commit is contained in:
Adriaan de Groot 2018-06-29 10:15:43 -04:00
parent 3329f2ea55
commit 22ee24a5ad

View File

@ -152,6 +152,26 @@ qmlDirCandidates( bool assumeBuilddir )
} }
static QStringList
settingsFileCandidates( bool assumeBuilddir )
{
static const char settings[] = "settings.conf";
QStringList settingsPaths;
if ( CalamaresUtils::isAppDataDirOverridden() )
settingsPaths << CalamaresUtils::appDataDir().absoluteFilePath( settings );
else
{
if ( assumeBuilddir )
settingsPaths << QDir::current().absoluteFilePath( settings );
settingsPaths << CMAKE_INSTALL_FULL_SYSCONFDIR "/calamares/settings.conf"; // String concat
settingsPaths << CalamaresUtils::appDataDir().absoluteFilePath( settings );
}
return settingsPaths;
}
void void
CalamaresApplication::initQmlPath() CalamaresApplication::initQmlPath()
{ {
@ -189,32 +209,10 @@ CalamaresApplication::initQmlPath()
void void
CalamaresApplication::initSettings() CalamaresApplication::initSettings()
{ {
QStringList settingsFileCandidatesByPriority = settingsFileCandidates( isDebug() );
QFileInfo settingsFile; QFileInfo settingsFile;
if ( CalamaresUtils::isAppDataDirOverridden() ) bool found = false;
{
settingsFile = QFileInfo( CalamaresUtils::appDataDir().absoluteFilePath( "settings.conf" ) );
if ( !settingsFile.exists() || !settingsFile.isReadable() )
{
cError() << "FATAL: explicitly configured application data directory"
<< CalamaresUtils::appDataDir().absolutePath()
<< "does not contain a valid settings.conf file."
<< "\nCowardly refusing to continue startup without settings.";
::exit( EXIT_FAILURE );
}
}
else
{
QStringList settingsFileCandidatesByPriority;
if ( isDebug() )
{
settingsFileCandidatesByPriority.append(
QDir::currentPath() +
QDir::separator() +
"settings.conf" );
}
settingsFileCandidatesByPriority.append( CMAKE_INSTALL_FULL_SYSCONFDIR "/calamares/settings.conf" );
settingsFileCandidatesByPriority.append( CalamaresUtils::appDataDir()
.absoluteFilePath( "settings.conf" ) );
foreach ( const QString& path, settingsFileCandidatesByPriority ) foreach ( const QString& path, settingsFileCandidatesByPriority )
{ {
@ -222,19 +220,21 @@ CalamaresApplication::initSettings()
if ( pathFi.exists() && pathFi.isReadable() ) if ( pathFi.exists() && pathFi.isReadable() )
{ {
settingsFile = pathFi; settingsFile = pathFi;
found = true;
break; break;
} }
} }
if ( !settingsFile.exists() || !settingsFile.isReadable() ) if ( !found || !settingsFile.exists() || !settingsFile.isReadable() )
{ {
cError() << "FATAL: none of the expected configuration file paths (" cError() << "Cowardly refusing to continue startup without settings."
<< settingsFileCandidatesByPriority.join( ", " ) << Logger::DebugList( settingsFileCandidatesByPriority );
<< ") contain a valid settings.conf file." if ( CalamaresUtils::isAppDataDirOverridden() )
<< "\nCowardly refusing to continue startup without settings."; cError() << "FATAL: explicitly configured application data directory is missing settings.conf";
else
cError() << "FATAL: none of the expected configuration file paths exist.";
::exit( EXIT_FAILURE ); ::exit( EXIT_FAILURE );
} }
}
new Calamares::Settings( settingsFile.absoluteFilePath(), isDebug(), this ); new Calamares::Settings( settingsFile.absoluteFilePath(), isDebug(), this );
} }